Make more use of xstrtoul()

This commit is contained in:
Přemysl Eric Janouch 2015-02-07 22:10:43 +01:00
parent 99116d0f70
commit 61ad99b611
3 changed files with 6 additions and 7 deletions

View File

@ -1350,10 +1350,8 @@ on_watch_primary_selection (G_GNUC_UNUSED const gchar *option_name,
return TRUE; return TRUE;
} }
char *end; unsigned long timer;
errno = 0; if (!xstrtoul (&timer, value, 10) || !timer || timer > G_MAXINT)
long timer = strtol (value, &end, 10);
if (errno || *end || end == value || timer <= 0 || timer > G_MAXINT)
{ {
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
_("Invalid timer value")); _("Invalid timer value"));

View File

@ -1,7 +1,7 @@
/* /*
* utils.c: miscellaneous utilities * utils.c: miscellaneous utilities
* *
* Copyright (c) 2013, Přemysl Janouch <p.janouch@gmail.com> * Copyright (c) 2013 - 2015, Přemysl Janouch <p.janouch@gmail.com>
* All rights reserved. * All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
@ -71,7 +71,7 @@ stream_read_string (GDataInputStream *dis, GError **error)
return s; return s;
} }
static bool gboolean
xstrtoul (unsigned long *out, const char *s, int base) xstrtoul (unsigned long *out, const char *s, int base)
{ {
char *end; char *end;

View File

@ -1,7 +1,7 @@
/* /*
* utils.h: miscellaneous utilities * utils.h: miscellaneous utilities
* *
* Copyright (c) 2013, Přemysl Janouch <p.janouch@gmail.com> * Copyright (c) 2013 - 2015, Přemysl Janouch <p.janouch@gmail.com>
* All rights reserved. * All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
@ -40,6 +40,7 @@
gboolean stream_read_all (GByteArray *ba, GInputStream *is, GError **error); gboolean stream_read_all (GByteArray *ba, GInputStream *is, GError **error);
gchar *stream_read_string (GDataInputStream *dis, GError **error); gchar *stream_read_string (GDataInputStream *dis, GError **error);
gboolean xstrtoul (unsigned long *out, const char *s, int base);
void update_curses_terminal_size (void); void update_curses_terminal_size (void);
#endif /* ! UTILS_H */ #endif /* ! UTILS_H */