diff options
author | Jeremy Huddleston <jeremyhu@apple.com> | 2011-05-08 10:02:16 -0700 |
---|---|---|
committer | Jeremy Huddleston <jeremyhu@apple.com> | 2011-05-08 10:02:54 -0700 |
commit | 6d83294bae9ba7394716f62abb08cfb8b89ed373 (patch) | |
tree | cafb12ca8cc3d15fff0f17fe3fdca642d25a34b7 | |
parent | 97085ba43fcd752271a9356c435d28b95211644d (diff) |
Rewrite parse_long to not fail -Wformat-nonliteral
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r-- | xwd.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -111,15 +111,26 @@ static int ReadColors(Visual *, Colormap, XColor **); static long parse_long (char *s) { - char *fmt = "%lu"; long retval = 0L; int thesign = 1; if (s && s[0]) { - if (s[0] == '-') s++, thesign = -1; - if (s[0] == '0') s++, fmt = "%lo"; - if (s[0] == 'x' || s[0] == 'X') s++, fmt = "%lx"; - (void) sscanf (s, fmt, &retval); + switch(s[0]) { + case '-': + (void) sscanf (s + 1, "%lu", &retval); + thesign = -1; + break; + case '0': + (void) sscanf (s + 1, "%lo", &retval); + break; + case 'x': + case 'X': + (void) sscanf (s + 1, "%lx", &retval); + break; + default: + (void) sscanf (s, "%lu", &retval); + break; + } } return (thesign * retval); } |