watch: use strtod_or_err() to validate user input

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-12-18 16:07:44 +01:00
parent 208a043256
commit 5862f47b96
2 changed files with 7 additions and 11 deletions

View File

@ -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

15
watch.c
View File

@ -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;