<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Den 2024-07-08 kl. 08:18, skrev Jan
Beulich:<br>
</div>
<blockquote type="cite"
cite="mid:3c0bf5f6-7756-4e9f-b9ab-b24b2f86771c@suse.com">
<pre class="moz-quote-pre" wrap="">On 05.07.2024 17:38, Ulf Samuelsson wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">
Den 2024-07-02 kl. 10:12, skrev Jan Beulich:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">First: Please don't drop the mailing list from Cc. Second: Please don't
top-post.
On 02.07.2024 00:21, Ulf Samuelsson wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">I submitted the code in this patch series more than a year ago, and it got accepted.
Then a lot was reverted since I had not assigned the copyright to FSF.
For unknown reasons, my ASCIZ patches remained, but the ASCII stuff was reverted.
The reason for the naming is to be similar to how I remember naming in some assemblers where ASCIZ is zero terminated and ASCII is not zero terminated.
If the string is too long, so it does not fit, it is really an error.
Adding a zero when truncating is a little less intrusive and may reduce runtime errors.
ASCII tells people what it is meant to be doing. ASCIIZ will make a lot of people wonder what the difference is between ASCIZ and ASCIIZ. It will also be misleading, because it does not add a zero if the string fits.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">Then did I read the code wrong? I was left with the impression that you'll
truncate at size-1, to ensure zero termination. Plus as you say in this
doc, size being 0 results in ASCIZ behavior, i.e. zero-terminates too.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
" 111111"
"0123456789012345"
ASCII (16) "This is a string"
results in 'size' == 16. Since the string is 16 characters, 'len'
will be 16 as well.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
And hence
else if (len >= size)
{
len = size - 1;
would reduce len down to 15 afaics, such that ...
</pre>
</blockquote>
<p>Given <b>ASCII 16, "This is 16 bytes</b>" size == 16 and
strlen("This is 16 bytes") == 16,<br>
the linker should add a 16 byte area without a terminating NUL,</p>
<p>If the string is shorter, then the linker should pad with NUL.</p>
<p>If the string is longer, then the linker should truncate the
string adding a NUL<br>
at the end, still fitting in the area. A warning should be issued.</p>
<p>You could issue an error, but a warning is less intrusive.<br>
</p>
<p>Checked again and it needs to be changed from</p>
<pre class="moz-quote-pre" wrap=""> else if (len >= size)
</pre>
<p>to<br>
</p>
<p></p>
<pre class="moz-quote-pre" wrap=""> else if (len > size)</pre>
<p>then the logic hopefully works out.</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:3c0bf5f6-7756-4e9f-b9ab-b24b2f86771c@suse.com">
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap=""> This loop will be run 16 times, and i will be 16 at the exit of
for (i = 0; i < len; i++)
lang_add_data (BYTE, exp_intop (string[i]));
Since i == 16, and size == 16, the following loop will not be run
even once.
while (i++ < size)
lang_add_data (BYTE, exp_intop ('\0'));
so no '\0' will be added.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
... a '\0' will be added here? Otherwise, if I continue to overlook
something, what I can say is that ...
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">===============================
ASCII (16) "This is a string."
size = 16, len = 17. len > size, solen is set to 16-1 = 15.
copy the first 15 characters in the first loop, add a single '\0' in
the second loop.
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
... this would be pretty odd to me: Why would a nul be inserted in
this case, but not in the one further up?
Jan
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Best Regards
Ulf Samuelsson</pre>
</body>
</html>