From 61ad99b611c454eaacc8709d313fa7db078eff29 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 7 Feb 2015 22:10:43 +0100
Subject: Make more use of xstrtoul()
---
src/sdtui.c | 6 ++----
src/utils.c | 4 ++--
src/utils.h | 3 ++-
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/sdtui.c b/src/sdtui.c
index 4961928..8456fb2 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -1350,10 +1350,8 @@ on_watch_primary_selection (G_GNUC_UNUSED const gchar *option_name,
return TRUE;
}
- char *end;
- errno = 0;
- long timer = strtol (value, &end, 10);
- if (errno || *end || end == value || timer <= 0 || timer > G_MAXINT)
+ unsigned long timer;
+ if (!xstrtoul (&timer, value, 10) || !timer || timer > G_MAXINT)
{
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
_("Invalid timer value"));
diff --git a/src/utils.c b/src/utils.c
index b7aa5da..7af0c2f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,7 +1,7 @@
/*
* utils.c: miscellaneous utilities
*
- * Copyright (c) 2013, Přemysl Janouch
+ * Copyright (c) 2013 - 2015, Přemysl Janouch
* All rights reserved.
*
* 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;
}
-static bool
+gboolean
xstrtoul (unsigned long *out, const char *s, int base)
{
char *end;
diff --git a/src/utils.h b/src/utils.h
index c3bdd84..8e43995 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -1,7 +1,7 @@
/*
* utils.h: miscellaneous utilities
*
- * Copyright (c) 2013, Přemysl Janouch
+ * Copyright (c) 2013 - 2015, Přemysl Janouch
* All rights reserved.
*
* 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);
gchar *stream_read_string (GDataInputStream *dis, GError **error);
+gboolean xstrtoul (unsigned long *out, const char *s, int base);
void update_curses_terminal_size (void);
#endif /* ! UTILS_H */
--
cgit v1.2.3-70-g09d2