[Scummvm-cvs-logs] scummvm master -> 52ebc0da38856c3105d58920ced048e024fda1d7

fuzzie fuzzie at fuzzie.org
Thu Jun 23 17:25:53 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
52ebc0da38 BASE: Correct usage of strtol().


Commit: 52ebc0da38856c3105d58920ced048e024fda1d7
    https://github.com/scummvm/scummvm/commit/52ebc0da38856c3105d58920ced048e024fda1d7
Author: Christoph Mallon (christoph.mallon at gmx.de)
Date: 2011-06-23T08:17:11-07:00

Commit Message:
BASE: Correct usage of strtol().

- endptr needs not be initialised before calling strtol(), it is always set by strtol().
- endptr is never a null pointer after calling strtol().
- There is no need to rely on strtol() setting EINVAL (which is not guaranteed).
  Testing whether strtol() parsed till the end of the string is sufficient (it is guaranteed that the string is not empty at this point).
- It is sufficient to just test for ERANGE without inspecting the return value, because a successful call to strtol() does not change errno.

Signed-off-by: Alyssa Milburn <fuzzie at fuzzie.org>

Changed paths:
    base/commandLine.cpp



diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 2620d69..5435116 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -26,7 +26,6 @@
 #define FORBIDDEN_SYMBOL_EXCEPTION_exit
 
 #include <errno.h>
-#include <limits.h>
 
 #include "engines/metaengine.h"
 #include "base/commandLine.h"
@@ -269,10 +268,10 @@ void registerDefaults() {
 // Use this for options which have a required integer value
 #define DO_OPTION_INT(shortCmd, longCmd) \
 	DO_OPTION(shortCmd, longCmd) \
-	char *endptr = 0; \
+	char *endptr; \
 	errno = 0; \
-	long int retval = strtol(option, &endptr, 0); \
-	if (endptr == NULL || *endptr != 0 || (errno != 0 && retval == 0) || (errno == ERANGE && (retval == LONG_MAX || retval == LONG_MIN))) \
+	strtol(option, &endptr, 0); \
+	if (*endptr != '\0' || errno == ERANGE) \
 		usage("--%s: Invalid number '%s'", longCmd, option);
 
 // Use this for boolean options; this distinguishes between "-x" and "-X",






More information about the Scummvm-git-logs mailing list