summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2011-05-08 10:02:16 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2011-05-08 10:02:54 -0700
commit6d83294bae9ba7394716f62abb08cfb8b89ed373 (patch)
treecafb12ca8cc3d15fff0f17fe3fdca642d25a34b7
parent97085ba43fcd752271a9356c435d28b95211644d (diff)
Rewrite parse_long to not fail -Wformat-nonliteral
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--xwd.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/xwd.c b/xwd.c
index 9ca67bc..30752f8 100644
--- a/xwd.c
+++ b/xwd.c
@@ -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);
}