From 718640ec0d212e8f3bf20005e35c1091646c9aea Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 22 Feb 2013 23:13:45 -0800 Subject: Use strtoul instead of open coding it with sscanf Signed-off-by: Alan Coopersmith --- xkill.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/xkill.c b/xkill.c index 8ee3431..2e3d7a3 100644 --- a/xkill.c +++ b/xkill.c @@ -52,7 +52,6 @@ static char *ProgramName; #define SelectButtonFirst (-2) static int parse_button ( char *s, int *buttonp ); -static XID parse_id ( char *s ); static XID get_window_id ( Display *dpy, int screen, int button, char *msg ); static int catch_window_errors ( Display *dpy, XErrorEvent *ev ); static int kill_all_windows ( Display *dpy, int screenno, Bool top ); @@ -113,7 +112,12 @@ main(int argc, char *argv[]) continue; case 'i': /* -id resourceid */ if (++i >= argc) usage (); - id = parse_id (argv[i]); + id = strtoul (argv[i], NULL, 0); + if (id == 0 || id >= 0xFFFFFFFFU) { + fprintf (stderr, "%s: invalid id \"%s\"\n", + ProgramName, argv[i]); + Exit (1, dpy); + } continue; case 'b': /* -button number */ if (++i >= argc) usage (); @@ -250,21 +254,6 @@ parse_button(char *s, int *buttonp) return (1); } - -static XID -parse_id(char *s) -{ - XID retval = None; - char *fmt = "%ld"; /* since XID is long */ - - if (s) { - if (*s == '0') s++, fmt = "%lo"; - if (*s == 'x' || *s == 'X') s++, fmt = "%lx"; - sscanf (s, fmt, &retval); - } - return (retval); -} - static XID get_window_id(Display *dpy, int screen, int button, char *msg) { -- cgit v1.2.3