Menu

#11 parsing minport: and maxport: config file

open
nobody
None
5
2007-10-08
2007-10-08
No

condition in the form:
...
*value = strtol( line, &endp, 10);
if (*endp != 0) {
...
does not render the right result in most cases. form example in my case it *endp would be "\n".

this patch actually checks for all failing condition of strtol to determine the error exit condition.

----------------------
--- a/src/context.c 2007-10-09 00:26:45.000000000 +0300
+++ b/src/context.c 2007-10-09 00:27:15.000000000 +0300
@@ -72,7 +72,7 @@
line += strspn( line, " \t");
*value = strtol( line, &endp, 10);

- if (*endp != 0) {
+ if ((0 == *value) || (LONG_MAX == *value) || (LONG_MIN == *value)) {
res = -1;
printf("In configuration file %s, line %d, the token %s failed to decode (%d)\n", file, lineno, token, res);
abort();
----------------------

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.