This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] [ARC] Fix handling of cpu=... disassembler option value
On 6/16/17 6:44 AM, Anton Kolesov wrote:
> FOR_EACH_DISASSEMBLER_OPTION advances pointer to the beginning of next option,
> but it doesn't create a new string with \0 at the end. So, for example, this
> code:
>
> const char* option;
> FOR_EACH_DISASSEMBLER_OPTION (option, "fpuda,fpud,fpus")
> {
> printf ("option: %s\n", option);
> }
That is true, but disassembler_options_cmp() treats ',' the same as '\0'
so disassembler_options_cmp ("fpuda", "fpuda,fpud,fpus") will return
that the strings match. That means you don't have to copy the next
option into a separate string just so you can terminate the string with
\0 before using strcmp(). Like ARC, ppc has problems using strncmp due
to multiple options having the same prefix string. So a loop like:
const char* option;
FOR_EACH_DISASSEMBLER_OPTION (option, "fpuda,fpud,fpus")
{
if (disassembler_options_cmp (option, "fpuda") == 0)
printf ("I found 'fpuda'\n");
else if (disassembler_options_cmp (option, "fpud") == 0)
printf ("I found 'fpud'\n");
else if (disassembler_options_cmp (option, "fpus") == 0)
printf ("I found 'fpus'\n");
}
will print:
I found 'fpuda'
I found 'fpud'
I found 'fpus'
Peter