From: H.G. Muller Date: Tue, 26 Jan 2010 18:28:43 +0000 (+0100) Subject: Fix of ancient WB bug: test integer option values for validity X-Git-Tag: master-20100206~20 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=f85f80fff1e9c9cb10f0d84ffd67d1df517dca3a;p=xboard.git Fix of ancient WB bug: test integer option values for validity Only a string of digits preceded by an optional sign is accepted now. Before, any string was accepted, and leaving out a value could lead to the next option being ignored (if it did not need a value) because it was considered the value for the previous one! --- diff --git a/args.h b/args.h index ff9b55b..e94c16b 100644 --- a/args.h +++ b/args.h @@ -699,6 +699,14 @@ ExitArgError(char *msg, char *badArg) exit(2); } +int +ValidateInt(char *s) +{ + char *p = s; + if(*p == '-' || *p == '+') p++; + while(*p) if(!isdigit(*p++)) ExitArgError("Bad integer value", s); + return atoi(s); +} char StringGet(void *getClosure) @@ -919,19 +927,19 @@ ParseArgs(GetFunc get, void *cl) switch (ad->argType) { case ArgInt: - *(int *) ad->argLoc = atoi(argValue); + *(int *) ad->argLoc = ValidateInt(argValue); break; case ArgX: - *(int *) ad->argLoc = atoi(argValue) + wpMain.x; // [HGM] placement: translate stored relative to absolute + *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.x; // [HGM] placement: translate stored relative to absolute break; case ArgY: - *(int *) ad->argLoc = atoi(argValue) + wpMain.y; // (this is really kludgey, it should be done where used...) + *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.y; // (this is really kludgey, it should be done where used...) break; case ArgZ: - *(int *) ad->argLoc = atoi(argValue); + *(int *) ad->argLoc = ValidateInt(argValue); EnsureOnScreen(&wpMain.x, &wpMain.y, minX, minY); break;