aboutsummaryrefslogtreecommitdiff
path: root/base/commandLine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'base/commandLine.cpp')
-rw-r--r--base/commandLine.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 6d187ac8b1..6cb858525e 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -25,6 +25,9 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
+#include <errno.h>
+#include <limits.h>
+
#include "engines/metaengine.h"
#include "base/commandLine.h"
#include "base/plugins.h"
@@ -267,8 +270,9 @@ void registerDefaults() {
#define DO_OPTION_INT(shortCmd, longCmd) \
DO_OPTION(shortCmd, longCmd) \
char *endptr = 0; \
+ errno = 0; \
long int retval = strtol(option, &endptr, 0); \
- if (endptr == NULL || *endptr != 0 || retval == 0 || retval == LONG_MAX || retval == LONG_MIN || errno == ERANGE) \
+ if (endptr == NULL || *endptr != 0 || (errno != 0 && retval == 0) || (errno == ERANGE && (retval == LONG_MAX || retval == LONG_MIN))) \
usage("--%s: Invalid number '%s'", longCmd, option);
// Use this for boolean options; this distinguishes between "-x" and "-X",