aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/command.c18
-rw-r--r--src/bin/psql/t/001_basic.pl17
2 files changed, 32 insertions, 3 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 955397ee9dc..61ec049f054 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2776,9 +2776,18 @@ exec_command_watch(PsqlScanState scan_state, bool active_branch,
/* Convert optional sleep-length argument */
if (opt)
{
- sleep = strtod(opt, NULL);
- if (sleep <= 0)
- sleep = 1;
+ char *opt_end;
+
+ errno = 0;
+ sleep = strtod(opt, &opt_end);
+ if (sleep < 0 || *opt_end || errno == ERANGE)
+ {
+ pg_log_error("\\watch: incorrect interval value '%s'", opt);
+ free(opt);
+ resetPQExpBuffer(query_buf);
+ psql_scan_reset(scan_state);
+ return PSQL_CMD_ERROR;
+ }
free(opt);
}
@@ -5183,6 +5192,9 @@ do_watch(PQExpBuffer query_buf, double sleep)
if (pagerpipe && ferror(pagerpipe))
break;
+ if (sleep == 0)
+ continue;
+
#ifdef WIN32
/*
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 0f394420b26..64ce0120621 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -350,4 +350,21 @@ psql_like(
'\copy from with DEFAULT'
);
+# Check \watch errors
+psql_fails_like(
+ $node,
+ 'SELECT 1;\watch -10',
+ qr/incorrect interval value '-10'/,
+ '\watch, negative interval');
+psql_fails_like(
+ $node,
+ 'SELECT 1;\watch 10ab',
+ qr/incorrect interval value '10ab'/,
+ '\watch incorrect interval');
+psql_fails_like(
+ $node,
+ 'SELECT 1;\watch 10e400',
+ qr/incorrect interval value '10e400'/,
+ '\watch out-of-range interval');
+
done_testing();