<?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[Frage zu sizeof]]></title><description><![CDATA[<p>Hallo wieso wird hier eine 5 anstatt eine 4 ausgeben ?</p>
<p>Wird der Nullterminator am ende von 0x90 auch mit gezählt ?</p>
<p>char s[] = &quot;\x41\x41\x00\x90&quot;;<br />
cout&lt;&lt;sizeof(s);</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272790/frage-zu-sizeof</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 15:43:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272790.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Aug 2010 10:22:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 10:22:42 GMT]]></title><description><![CDATA[<p>Hallo wieso wird hier eine 5 anstatt eine 4 ausgeben ?</p>
<p>Wird der Nullterminator am ende von 0x90 auch mit gezählt ?</p>
<p>char s[] = &quot;\x41\x41\x00\x90&quot;;<br />
cout&lt;&lt;sizeof(s);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944140</guid><dc:creator><![CDATA[sizeof]]></dc:creator><pubDate>Wed, 25 Aug 2010 10:22:42 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 10:33:10 GMT]]></title><description><![CDATA[<p>Ja. Du kriegst hier die Anzahl der Bytes deines Arrays, und das beinhaltet 5 char's.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944143</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Wed, 25 Aug 2010 10:33:10 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 10:35:19 GMT]]></title><description><![CDATA[<p>sizeof schrieb:</p>
<blockquote>
<p>Hallo wieso wird hier eine 5 anstatt eine 4 ausgeben ?</p>
<p>Wird der Nullterminator am ende von 0x90 auch mit gezählt ?</p>
<p>char s[] = &quot;\x41\x41\x00\x90&quot;;<br />
cout&lt;&lt;sizeof(s);</p>
</blockquote>
<p>Ja natürlich, dafür brauchst du ja auch Platz. Wenn du die Länge des Strings wissen willst, benötigst du strlen.</p>
<p>Besser wäre in einem C++-Programm aber die Verwendung von std::string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944144</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 25 Aug 2010 10:35:19 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 10:56:37 GMT]]></title><description><![CDATA[<p>strlen wird nicht funktionieren \x00 &lt;-- Nullterminator <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>std::string wird auch durch \x00 Terminiert :&gt;</p>
<p>Deswegen verwende ich für mein Shellcode char []</p>
<p>char s[]= &quot;\xeb\x50\x5b\x53\xb8\x7b\x1d\x80\x7c\xff\xd0\xe8\x35\x00\x00\x00\x5b\x53\x50\xba\x40\xae\x80\x7c\xff\xd2\xe8\x18\x00\x00\x00\x5b\x68\x00\x00\x00\x00\x53\xff\xd0\xe8\x00\x00\x00\x00\x31\xc0\x50\xb8\x12\xcb\x81\x7c\xff\xd0\xe8\xe3\xff\xff\xff\x63\x61\x6c\x63\x2e\x65\x78\x65\x00\xe8\xc6\xff\xff\xff\x57\x69\x6e\x45\x78\x65\x63\x00\xe8\xab\xff\xff\xff\x6b\x65\x72\x6e\x65\x6c\x33\x32\x2e\x64\x6c\x6c\x00&quot;;</p>
<pre><code>[Section .text]
BITS 32
global _start

_start:

jmp short GetDLLname 

LoadLib: 
				pop  ebx  ; ebx = kernel32.dll
				push ebx 
				mov  eax , 0x7c801d7b ; LoadLibrary Addr    
				call eax  ; call LoadLibrary  return wert in eax

				call GetFuncName

GetDllAddr:
				pop ebx   ; ebx = WinExec
				push ebx        ; WinExec 				
				push eax        ; handle von LoadLibrary

				mov edx,0x7c80ae40  ; GetProcAddress addr 
				call edx 	        ; call GetProcAdress  return addr in eax			
				call ExecName

ExecProg:
				pop ebx

				push 0
				push ebx	
				call eax  ; addr von WinExec 

				call ExitProg

ExitProg:
				xor eax,eax
				push eax
				mov eax,0x7c81cb12
			    call eax

ExecName:
				call ExecProg
				db &quot;calc.exe&quot;
				db 00

GetFuncName:
				call GetDllAddr
				db &quot;WinExec&quot;
				db 00

GetDLLname:

				call LoadLib 
				db &quot;kernel32.dll&quot; 
				db 0x00
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1944151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944151</guid><dc:creator><![CDATA[sizeof]]></dc:creator><pubDate>Wed, 25 Aug 2010 10:56:37 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 11:10:18 GMT]]></title><description><![CDATA[<p>sizeof schrieb:</p>
<blockquote>
<p>std::string wird auch durch \x00 Terminiert :&gt;</p>
</blockquote>
<p>Nein, ein std::string kann \0 im Text enthalten und ist am Ende nicht notwendigerweise mit einem \0 abgeschlossen.</p>
<p>Aber für Shellcode würde ich ihn auch nicht verwenden, denn da willst du ja etwas kaputt machen <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1944159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944159</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 25 Aug 2010 11:10:18 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 11:38:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::string var= &quot;\x41\x41\x00\x41\x41&quot;;

std::cout &lt;&lt; var;
</code></pre>
<pre><code class="language-cpp">std::string var[] = {&quot;\x41\x41\x00\x41\x41&quot;};

        for (int i=0;i&lt;=sizeof(var);i++)
        {
             std::cout&lt;&lt;var[i];
        }
</code></pre>
<p>Gibt beides bei mir aus: AA</p>
<p>Auch std::string wird durch \x00 Terminiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944180</guid><dc:creator><![CDATA[sizeof]]></dc:creator><pubDate>Wed, 25 Aug 2010 11:38:51 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 11:42:31 GMT]]></title><description><![CDATA[<p>Das liegt daran, wie du den String initialisierst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944183</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944183</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 25 Aug 2010 11:42:31 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 11:43:40 GMT]]></title><description><![CDATA[<p>sizeof schrieb:</p>
<blockquote>
<pre><code class="language-cpp">std::string var= &quot;\x41\x41\x00\x41\x41&quot;;
</code></pre>
<p>Auch std::string wird durch \x00 Terminiert.</p>
</blockquote>
<p>Nein, bei der Initialisierung über einen <code>const char*</code> wird nur bis zum \0 kopiert (woher soll der Konstruktor auch wissen, dass das String-Literal noch länger ist?). Du kannst aber z.B.</p>
<pre><code class="language-cpp">std::string var(&quot;\x41\x41\x00\x41\x41&quot;, 5);
assert(var.length() == 5);
</code></pre>
<p>sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944185</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 25 Aug 2010 11:43:40 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 11:45:46 GMT]]></title><description><![CDATA[<p>sizeof schrieb:</p>
<blockquote>
<pre><code class="language-cpp">std::string var= &quot;\x41\x41\x00\x41\x41&quot;;

std::cout &lt;&lt; var;
</code></pre>
<pre><code class="language-cpp">std::string var[] = {&quot;\x41\x41\x00\x41\x41&quot;};

        for (int i=0;i&lt;=sizeof(var);i++)
        {
             std::cout&lt;&lt;var[i];
        }
</code></pre>
<p>Gibt beides bei mir aus: AA</p>
<p>Auch std::string wird durch \x00 Terminiert.</p>
</blockquote>
<p>Oho, Beweis durch Beispiel. Auch bekannt als &quot;Das beweist überhaupt nichts&quot;. std::string braucht keine Nullterminierung zu haben und man darf sich darauf nicht verlassen, auch wenn bei deiner speziellen Implementierung vielleicht manchmal ein Nullzeichen folgt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944186</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 25 Aug 2010 11:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 12:21:39 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>std::string braucht keine Nullterminierung zu haben und man darf sich darauf nicht verlassen, auch wenn bei deiner speziellen Implementierung vielleicht manchmal ein Nullzeichen folgt.</p>
</blockquote>
<p>Doch, man kann sich drauf verlassen, dass std::string <em>nicht</em> nullterminiert ist. Die Annahme, es sei doch so, beruht hier auf einer Fehlinterpretation, siehe die zwei Postings vor dir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944202</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 25 Aug 2010 12:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 12:26:11 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>std::string braucht keine Nullterminierung zu haben und man darf sich darauf nicht verlassen, auch wenn bei deiner speziellen Implementierung vielleicht manchmal ein Nullzeichen folgt.</p>
</blockquote>
<p>Doch, man kann sich drauf verlassen, dass std::string <em>nicht</em> nullterminiert ist. Die Annahme, es sei doch so, beruht hier auf einer Fehlinterpretation, siehe die zwei Postings vor dir.</p>
</blockquote>
<p>Sicher? Ich bin mir ziemlich sicher, dass std::string auch eine Nullterminierung am Ende haben darf. Wäre zwar dumm das so zu implementieren, aber laut Standard dürfte nichts dagegen sprechen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944204</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 25 Aug 2010 12:26:11 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 12:52:06 GMT]]></title><description><![CDATA[<p>Ja, sicher. Lies es nach, 21.3§1:<br />
&quot;the template class basic_string describes objects that can store a sequence consisting of a varying number of <strong>arbitrary</strong> char-like objects&quot;</p>
<p>Wenn du recht hättest, dürfte bei dem Code:</p>
<pre><code class="language-cpp">std::string var(&quot;\x41\x41\x00\x41\x41&quot;, 5);
assert(var.length() == 5);
</code></pre>
<p>je nach Lust und Laune des Compilerherstellers die Assertion fehlschlagen.</p>
<p>Der Konstruktor von std::string hat aber als Nachbedingung, dass size() bzw. length() gleich der übergebenen Länge ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944225</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944225</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 25 Aug 2010 12:52:06 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 12:58:24 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Ja, sicher. Lies es nach, 21.3§1:<br />
&quot;the template class basic_string describes objects that can store a sequence consisting of a varying number of <strong>arbitrary</strong> char-like objects&quot;</p>
<p>Wenn du recht hättest, dürfte bei dem Code:</p>
<pre><code class="language-cpp">std::string var(&quot;\x41\x41\x00\x41\x41&quot;, 5);
assert(var.length() == 5);
</code></pre>
<p>je nach Lust und Laune des Compilerherstellers die Assertion fehlschlagen.</p>
<p>Der Konstruktor von std::string hat aber als Nachbedingung, dass size() bzw. length() gleich der übergebenen Länge ist.</p>
</blockquote>
<p>Ich glaube, du verstehst das mit dem Nullterminiert falsch. Das soll nicht bedeuten, dass bei einem \0 der String zu ende ist, sondern nur, dass hinter dem letzen gültigen Zeichen eine \0 stehen kann, aber nicht muss. Im String selber können beliebig viele \0 stehen und die ändern auch nichts an der Länge.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944230</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 25 Aug 2010 12:58:24 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 12:59:25 GMT]]></title><description><![CDATA[<p>Es soll ja auch nicht das Ende <strong>markieren</strong>. Die Implementierung darf doch am Ende des Speicherbereichs beliebige Zeichen anfügen. Es reicht ja, dass length, size &amp; Co die richtigen Werte liefern. Auf diese Weise könnte man sich beispielsweise bei der Funktion c_str() das Anhängen der Null sparen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944232</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 25 Aug 2010 12:59:25 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 13:08:28 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Es soll ja auch nicht das Ende markieren.</p>
</blockquote>
<p>Doch, sonst ist es was anderes. Null-terminiert bedeutet, dass das Ende durch Null angezeigt wird.<br />
Was std::string außerhalb des zugreifbaren Bereichs anhängt, interessiert doch keinen. Da darf std::string es gerne eine Null anhängen, das ist auch gar nicht mal soo dumm, weil dann c_str() trivial (= performanter) implementiert werden kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944238</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 25 Aug 2010 13:08:28 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 13:14:33 GMT]]></title><description><![CDATA[<p>Ok, dann war das wohl nur ein Missverständnis wegen falscher Wortwahl. Genau das meinte ich nämlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944242</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 25 Aug 2010 13:14:33 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 15:42:51 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Es soll ja auch nicht das Ende markieren.</p>
</blockquote>
<p>Doch, sonst ist es was anderes. Null-terminiert bedeutet, dass das Ende durch Null angezeigt wird.<br />
Was std::string außerhalb des zugreifbaren Bereichs anhängt, interessiert doch keinen. Da darf std::string es gerne eine Null anhängen, das ist auch gar nicht mal soo dumm, weil dann c_str() trivial (= performanter) implementiert werden kann.</p>
</blockquote>
<p>Die Komplexitätsanforderungen an c_str() bzw. data() erfordern das sogar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944303</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 25 Aug 2010 15:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 16:03:08 GMT]]></title><description><![CDATA[<p>Komplexitätsanforderungen an c_str oder data finde ich in C++98 nicht, wo stehen die?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944314</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Wed, 25 Aug 2010 16:03:08 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu sizeof on Wed, 25 Aug 2010 16:16:31 GMT]]></title><description><![CDATA[<p>Finde ich zwar auch nicht, aber ein ganz fieser Implementierer könnte ja auch mehrere Kopien der Stringdaten halten. Oder immer schon ein paar Zeichen mehr reservieren, die aber nicht 0 gesetzt werden, sondern nur wenn tatsächlich c_str() benutzt wird. Damit könnte man auch ohne 0 am Ende der eigentlichen Daten eine konstante Zeitkomplexitat erreichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1944318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1944318</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 25 Aug 2010 16:16:31 GMT</pubDate></item></channel></rss>