<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fehler bei switch]]></title><description><![CDATA[<p>Hallo zusmmen,</p>
<p>leider erhalte ich folgenden Fehler:</p>
<p>Run-Time Check Failure #2 - Stack around the variable 'write_buffer' was corrupted.</p>
<pre><code class="language-cpp">char write_buffer[10] = {' '};

...

// Der Write funktioniert, die Variable wird geschrieben und später kommt auch ein Wert per Read zurück, d.h. der Wert wird geschrieben und gelesen

	if(!WriteFile(hSerial, &amp;write_buffer, n, &amp;dwBytesWrite, NULL))
	{
		//error occurred. Report to user
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei WriteFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

// Nach dem switch, der am Ende der Funktion steht knallt es, wieso?
	switch ( buffer_ende[2] )
	{
	case 'lX':
		newsize = strlen(read_buffer) + 1;
		origsize = wcslen(a_buffer_lX_co) + 1;
		mbstowcs_s(&amp;convertedChars,a_buffer_lX_co,newsize,read_buffer,_TRUNCATE);
		break;

	case 'Y':
		i++;
		break;
	}
</code></pre>
<p>Hier die ganze Funktion:</p>
<pre><code class="language-cpp">void ReadAndWrite(HWND hwnd, wchar_t p_wchar_T[10])
{
	char write_buffer[10] = {' '};
	char read_buffer[10] = {' '};
	char buffer_ende[2] = {' '};
	size_t newsize = strlen(write_buffer) + 1;
	size_t origsize = wcslen(p_wchar_T) + 1;
	size_t convertedChars = 0;
	int i = 0;

	wcstombs_s(&amp;convertedChars, write_buffer, origsize, p_wchar_T, _TRUNCATE);
	//wcstombs_s(&amp;convertedChars, write_buffer, origsize, buffer_lX, _TRUNCATE);

	if(!WriteFile(hSerial, &amp;write_buffer, n, &amp;dwBytesWrite, NULL))
	{
		//error occurred. Report to user
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei WriteFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

	if(!ReadFile(hSerial, &amp;read_buffer, n, &amp;dwBytesRead, NULL))
	{
		//error occurred. Report to user.
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei ReadFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

	// Da man nicht genau weiß, welcher Joystickwert zurück kommt, muss man auf die letzten beiden Stellen abfragen, 
	// dort steht welcher Joystickwert gelesen wurde	

	buffer_ende[0] = read_buffer[5];
	buffer_ende[1] = read_buffer[6];

	switch ( buffer_ende[2] )
	{
	case 'lX':
		newsize = strlen(read_buffer) + 1;
		origsize = wcslen(a_buffer_lX_co) + 1;
		mbstowcs_s(&amp;convertedChars,a_buffer_lX_co,newsize,read_buffer,_TRUNCATE);
		break;

	case 'Y':
		i++;
		break;
	}
}
</code></pre>
<p>Hat jemand eine Idee?</p>
<p>Vielen Dank</p>
<p>datatom</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/289061/fehler-bei-switch</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 16:11:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/289061.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 27 Jun 2011 19:47:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 19:47:58 GMT]]></title><description><![CDATA[<p>Hallo zusmmen,</p>
<p>leider erhalte ich folgenden Fehler:</p>
<p>Run-Time Check Failure #2 - Stack around the variable 'write_buffer' was corrupted.</p>
<pre><code class="language-cpp">char write_buffer[10] = {' '};

...

// Der Write funktioniert, die Variable wird geschrieben und später kommt auch ein Wert per Read zurück, d.h. der Wert wird geschrieben und gelesen

	if(!WriteFile(hSerial, &amp;write_buffer, n, &amp;dwBytesWrite, NULL))
	{
		//error occurred. Report to user
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei WriteFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

// Nach dem switch, der am Ende der Funktion steht knallt es, wieso?
	switch ( buffer_ende[2] )
	{
	case 'lX':
		newsize = strlen(read_buffer) + 1;
		origsize = wcslen(a_buffer_lX_co) + 1;
		mbstowcs_s(&amp;convertedChars,a_buffer_lX_co,newsize,read_buffer,_TRUNCATE);
		break;

	case 'Y':
		i++;
		break;
	}
</code></pre>
<p>Hier die ganze Funktion:</p>
<pre><code class="language-cpp">void ReadAndWrite(HWND hwnd, wchar_t p_wchar_T[10])
{
	char write_buffer[10] = {' '};
	char read_buffer[10] = {' '};
	char buffer_ende[2] = {' '};
	size_t newsize = strlen(write_buffer) + 1;
	size_t origsize = wcslen(p_wchar_T) + 1;
	size_t convertedChars = 0;
	int i = 0;

	wcstombs_s(&amp;convertedChars, write_buffer, origsize, p_wchar_T, _TRUNCATE);
	//wcstombs_s(&amp;convertedChars, write_buffer, origsize, buffer_lX, _TRUNCATE);

	if(!WriteFile(hSerial, &amp;write_buffer, n, &amp;dwBytesWrite, NULL))
	{
		//error occurred. Report to user
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei WriteFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

	if(!ReadFile(hSerial, &amp;read_buffer, n, &amp;dwBytesRead, NULL))
	{
		//error occurred. Report to user.
		msgboxIDss = MessageBox(NULL, (LPCWSTR)L&quot;Fehler bei ReadFile!&quot;,
			(LPCWSTR)L&quot;Fehler&quot;, MB_OK | MB_ICONEXCLAMATION);
		EndDialog(hwnd, 1);
	}

	// Da man nicht genau weiß, welcher Joystickwert zurück kommt, muss man auf die letzten beiden Stellen abfragen, 
	// dort steht welcher Joystickwert gelesen wurde	

	buffer_ende[0] = read_buffer[5];
	buffer_ende[1] = read_buffer[6];

	switch ( buffer_ende[2] )
	{
	case 'lX':
		newsize = strlen(read_buffer) + 1;
		origsize = wcslen(a_buffer_lX_co) + 1;
		mbstowcs_s(&amp;convertedChars,a_buffer_lX_co,newsize,read_buffer,_TRUNCATE);
		break;

	case 'Y':
		i++;
		break;
	}
}
</code></pre>
<p>Hat jemand eine Idee?</p>
<p>Vielen Dank</p>
<p>datatom</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085071</guid><dc:creator><![CDATA[datatom]]></dc:creator><pubDate>Mon, 27 Jun 2011 19:47:58 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 19:53:25 GMT]]></title><description><![CDATA[<p>Und wo hast du n definiert? Hast du sichergestellt, daß der Wert nicht zu groß ist, um in deine Arrays zu passen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085079</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 27 Jun 2011 19:53:25 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 20:00:43 GMT]]></title><description><![CDATA[<p>Ich weiß gar nicht wozu n da ist:-(</p>
<pre><code class="language-cpp">int n = 10;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2085084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085084</guid><dc:creator><![CDATA[datatom]]></dc:creator><pubDate>Mon, 27 Jun 2011 20:00:43 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 20:13:27 GMT]]></title><description><![CDATA[<p>datatom schrieb:</p>
<blockquote>
<p>Ich weiß gar nicht wozu n da ist:-(</p>
</blockquote>
<p>Du benutzt es aber in Zeile 14 und 22 <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Ansonsten liegt der Wert <code>buffer_ende[2]</code> , den du im switch abfragst, außerhalb des erlaubten Index - und die Größenangabe für den Funktionsparameter wird btw vom Compiler nicht berücksichtigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085095</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 27 Jun 2011 20:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 20:22:15 GMT]]></title><description><![CDATA[<p>Können die Compiler heute auch so was:</p>
<pre><code class="language-cpp">switch ( buffer_ende[2] )
    {
    case 'lX':
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085098</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Mon, 27 Jun 2011 20:22:15 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 20:28:18 GMT]]></title><description><![CDATA[<p>Wenn du mir erklärst, was 'lX' ist.</p>
<p>Edit: Ach sorry, du hast das kopiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085099</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 27 Jun 2011 20:28:18 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 20:55:37 GMT]]></title><description><![CDATA[<p>Früher war das einfach - switch konnte Werte von -1 bis 255 (?)</p>
<p>Kann switch in entsprechendem Umfeld auch Unicode?<br />
Microsoft kann da scheint es mehr:<br />
<a href="http://msdn.microsoft.com/en-us/library/k0t5wee3%28v=vs.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/k0t5wee3(v=vs.80).aspx</a></p>
<p>Wie sieht das da aus bezüglich C++0x<br />
oder was machen die anderen Compilerlieferanten?</p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085112</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Mon, 27 Jun 2011 20:55:37 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Mon, 27 Jun 2011 21:03:49 GMT]]></title><description><![CDATA[<p>f.-th. schrieb:</p>
<blockquote>
<p>Früher war das einfach - switch konnte Werte von -1 bis 255 (?)</p>
</blockquote>
<p>Hast du dazu auch eine offizielle Aussage? Ich finde zwar die Festlegung, daß der Compiler mindestens 257 case-Marken unterstützen muß, aber nichts zum erlaubten Wertebereich der case-Konstanten</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085115</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 27 Jun 2011 21:03:49 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Tue, 28 Jun 2011 06:48:23 GMT]]></title><description><![CDATA[<p>Offiziell nein.</p>
<p>2^8 + 1 = 257</p>
<p>Ich unterstelle mal das 0 bis 255 von allen Compilern verstanden wird.<br />
Da ist halt die 257ste Marke, wo sollen wir damit hin? Die passt ja nicht mehr in ein Byte. Irgend woher benötigen wir mindestens noch ein Bit.</p>
<p>Da mir so etwas keine Ruhe lässt:<br />
<a href="http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.htm" rel="nofollow">http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n843.htm</a><br />
sagt 1023 case labels.</p>
<p>Aber vielleicht findet oder kennt ja jemand noch eine andere Variante <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085232</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Tue, 28 Jun 2011 06:48:23 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei switch on Tue, 28 Jun 2011 07:01:28 GMT]]></title><description><![CDATA[<p>Oh, die 1023 gehören ja zum C99 Entwurf.</p>
<p>Gilt da bei C++0whatever das gleiche oder noch 257 case label <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>MfG f.-th.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2085240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2085240</guid><dc:creator><![CDATA[f.-th.]]></dc:creator><pubDate>Tue, 28 Jun 2011 07:01:28 GMT</pubDate></item></channel></rss>