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_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c
slabtop_LDADD = @NCURSES_LIBS@ slabtop_LDADD = @NCURSES_LIBS@
top_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 endif
kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c 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; option_exec = 1;
break; break;
case 'n': case 'n':
{ interval = strtod_or_err(optarg, _("failed to parse argument"));
char *str; if (interval < 0.1)
interval = strtod(optarg, &str); interval = 0.1;
if (!*optarg || *str) if (interval > ~0u / 1000000)
usage(stderr); interval = ~0u / 1000000;
if (interval < 0.1)
interval = 0.1;
if (interval > ~0u / 1000000)
interval = ~0u / 1000000;
}
break; break;
case 'p': case 'p':
precise_timekeeping = 1; precise_timekeeping = 1;