- errno = 0;
- dynamic_space_size = strtol(argv[argi++], 0, 0) << 20;
- if (errno)
- lose("argument to --dynamic-space-size is not a number");
+ {
+ char *tail;
+ long tmp = strtol(argv[argi++], &tail, 0);
+ if (tail[0])
+ lose("--dynamic-space-size argument is not a number");
+ if ((tmp <= 0) ||
+ (tmp >= (LONG_MAX >> 20))) {
+ lose("--dynamic-space-size argument is out of range");
+ }
+ dynamic_space_size = tmp << 20;
+ }