Commit 88cfcbb7 authored by Peter Eisentraut's avatar Peter Eisentraut

pg_amcheck: Fix block number parsing on command line

The previous code wouldn't handle higher block numbers on systems
where sizeof(long) == 4.
Reviewed-by: default avatarMark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/6a10a211-872b-3c4c-106b-909ae5fefa61%40enterprisedb.com
parent 46490039
...@@ -297,6 +297,7 @@ main(int argc, char *argv[]) ...@@ -297,6 +297,7 @@ main(int argc, char *argv[])
long_options, &optindex)) != -1) long_options, &optindex)) != -1)
{ {
char *endptr; char *endptr;
unsigned long optval;
switch (c) switch (c)
{ {
...@@ -409,30 +410,34 @@ main(int argc, char *argv[]) ...@@ -409,30 +410,34 @@ main(int argc, char *argv[])
} }
break; break;
case 7: case 7:
opts.startblock = strtol(optarg, &endptr, 10); errno = 0;
if (*endptr != '\0') optval = strtoul(optarg, &endptr, 10);
if (endptr == optarg || *endptr != '\0' || errno != 0)
{ {
pg_log_error("invalid start block"); pg_log_error("invalid start block");
exit(1); exit(1);
} }
if (opts.startblock > MaxBlockNumber || opts.startblock < 0) if (optval > MaxBlockNumber)
{ {
pg_log_error("start block out of bounds"); pg_log_error("start block out of bounds");
exit(1); exit(1);
} }
opts.startblock = optval;
break; break;
case 8: case 8:
opts.endblock = strtol(optarg, &endptr, 10); errno = 0;
if (*endptr != '\0') optval = strtoul(optarg, &endptr, 10);
if (endptr == optarg || *endptr != '\0' || errno != 0)
{ {
pg_log_error("invalid end block"); pg_log_error("invalid end block");
exit(1); exit(1);
} }
if (opts.endblock > MaxBlockNumber || opts.endblock < 0) if (optval > MaxBlockNumber)
{ {
pg_log_error("end block out of bounds"); pg_log_error("end block out of bounds");
exit(1); exit(1);
} }
opts.endblock = optval;
break; break;
case 9: case 9:
opts.rootdescend = true; opts.rootdescend = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment