[PATCH v1 4/7] ld.texi: Add ASCII to info file

Ulf Samuelsson ulf@emagii.com
Mon Jul 8 12:01:25 GMT 2024


Den 2024-07-08 kl. 13:48, skrev Andreas Schwab:
> On Jul 08 2024, Ulf Samuelsson wrote:
>
>> Den 2024-07-08 kl. 13:18, skrev Andreas Schwab:
>>> On Jul 08 2024, Ulf Samuelsson wrote:
>>>
>>>> Given *ASCII 16, "This is 16 bytes*"  size == 16 and strlen("This is 16
>>>> bytes") == 16,
>>>> the linker should add a 16 byte area without a terminating NUL,
>>>>
>>>> If the string is shorter, then the linker should pad with NUL.
>>>>
>>>> If the string is longer, then the linker should truncate the string adding
>>>> a NUL
>>>> at the end, still fitting in the area. A warning should be issued.
>>> This inonsistency is confusing.  The directive should either always use
>>> the first size characters from the string, only padding with nulls when
>>> the string is shorter, or reject longer strings at all.
>>>
>> I do not see that the user can be confused if the user reads the warning
>> message:
>>
>> "warning: ASCII string does not fit in allocated space, truncated"
> That does not tell the whole truth.  ASCII 4, "foob" gives you a 4 byte
> string, but ASCII 4, "foobar" gives you a three byte string.

ASCII 4, "foob" gives you a 4 byte area which is not a zero-terminated 
string.
If you intended it to be a zero-terminated string, there is an uncatched 
bug.

ASCII 4, "foobar" gives you a 4 byte area which is different from your 
intention and a warning message.
It also tries to minimizes the damage of your mistake.


>
-- 
Best Regards,
Ulf Samuelsson
eMagii
+46 722 427437
ulf@emagii.com



More information about the Binutils mailing list