On 2013/7/14 09:27 PM, Joseph S. Myers wrote: > On Sun, 14 Jul 2013, Chung-Lin Tang wrote: > >> Original patch posted as part of Nios II patches: >> http://gcc.gnu.org/ml/gcc-patches/2013-04/msg01087.html >> >> This patch is to allow hexadecimal numbers to be used in option >> arguments, e.g. -falign-loops=0x10 can now be used as equivalent to >> -falign-loops=16. >> >> Joseph, the patch has been modified to use IXDIGIT to check the argument >> string first, as you suggested in the last submission. Is this okay for >> trunk? > > This version looks like it will allow plain "0x" or "0X" as an argument, > treating it as 0, rather than treating it as an error (i.e., you need to > check there is at least one hex digit after the "0x" or "0X" before > passing the string to strtol). >
Hi Joseph, Forgot to follow up on this patch. Here it is with a small update to check if 'p' got updated to a difference position. Does this now look okay? Thanks, Chung-Lin
Index: opts-common.c =================================================================== --- opts-common.c (revision 205847) +++ opts-common.c (working copy) @@ -147,7 +147,7 @@ find_opt (const char *input, unsigned int lang_mas return match_wrong_lang; } -/* If ARG is a non-negative integer made up solely of digits, return its +/* If ARG is a non-negative decimal or hexadecimal integer, return its value, otherwise return -1. */ int @@ -161,6 +161,17 @@ integral_argument (const char *arg) if (*p == '\0') return atoi (arg); + /* It wasn't a decimal number - try hexadecimal. */ + if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X')) + { + p = arg + 2; + while (*p && ISXDIGIT (*p)) + p++; + + if (p != arg + 2 && *p == '\0') + return strtol (arg, NULL, 16); + } + return -1; }