[PATCH v5 05/20] gas: implement parsing of object attributes v2

Richard Earnshaw (lists) Richard.Earnshaw@arm.com
Thu Jul 10 09:57:51 GMT 2025


On 09/07/2025 16:05, Matthieu Longo wrote:
> On 2025-07-09 14:55, Richard Earnshaw (lists) wrote:
>> On 07/07/2025 17:49, Matthieu Longo wrote:
>>> diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
>>> index 1ccbcc40d4d..acf93a3cee5 100644
>>> --- a/bfd/elf-attrs.c
>>> +++ b/bfd/elf-attrs.c
>>> +
>>> +/* Return True if the given subsection name is part of the reserved "gnu-testing"
>>> +   namespace.  */
>>> +static bool
>>> +gnu_testing_namespace (const char *subsec_name)
>>> +{
>>> +  return strncmp ("gnu-testing", subsec_name, 11) == 0;
>>
>> What's the reason for using strncmp here rather than strcmp?
>>
> 
> The subsection name can be longer than "gnu-testing" (see example in the tests), so we need to compare at most len("gnu-testing"), i.e. 11 bytes.
> In my understanding, you cannot do this with strcmp.

No, you can't but this would match a section called "gnu-testing-for-christmas", which doesn't really seem correct: it's not the gnu-testing subsection.  If subsec_name isn't null terminated, then it would be reasonable to use strncmp, but then you'd want to pass the length limit as an argument to this function.


But maybe I've misunderstood how the naming scheme works here.  Perhaps this *is* supposed to be a prefix to longer strings.  But in that case:
1) I think the comment could be a bit clearer.
2) I think you should check that subsec_name[11] is not '\0', since then the string is not a prefix.


R.


More information about the Binutils mailing list