From 5862f47b96afe21490c7d891b492bd31003ab77a Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 18 Dec 2011 16:07:44 +0100 Subject: [PATCH] watch: use strtod_or_err() to validate user input Signed-off-by: Sami Kerola --- Makefile.am | 3 ++- watch.c | 15 +++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 389c1928..fbf9ec40 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,7 +61,8 @@ dist_man_MANS += \ slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c slabtop_LDADD = @NCURSES_LIBS@ top_LDADD = @NCURSES_LIBS@ -watch_LDADD = @WATCH_NCURSES_LIBS@ +watch_SOURCES = watch.c $(top_srcdir)/lib/strutils.c +watch_LDADD = @NCURSES_LIBS@ endif kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c diff --git a/watch.c b/watch.c index 13f3c4e9..8fb05b1c 100644 --- a/watch.c +++ b/watch.c @@ -337,16 +337,11 @@ int main(int argc, char *argv[]) option_exec = 1; break; case 'n': - { - char *str; - interval = strtod(optarg, &str); - if (!*optarg || *str) - usage(stderr); - if (interval < 0.1) - interval = 0.1; - if (interval > ~0u / 1000000) - interval = ~0u / 1000000; - } + interval = strtod_or_err(optarg, _("failed to parse argument")); + if (interval < 0.1) + interval = 0.1; + if (interval > ~0u / 1000000) + interval = ~0u / 1000000; break; case 'p': precise_timekeeping = 1;