diff options
author | Andrey Nazarov <skuller@skuller.net> | 2013-01-06 21:13:16 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2013-01-07 14:54:56 +0400 |
commit | 5f9eed3c3478a0ab5d01018b343ec39cb22a173e (patch) | |
tree | 53706249655117889d4c7219e398a16177c916b3 | |
parent | 5ecbf20d85b39e20c6d12f6839c02a780825297c (diff) |
Fix some scan-build detected issues.
Fix potential crash when parsing unknown long options. Silence a few
warnings.
-rw-r--r-- | src/client/ascii.c | 1 | ||||
-rw-r--r-- | src/client/entities.c | 2 | ||||
-rw-r--r-- | src/client/parse.c | 2 | ||||
-rw-r--r-- | src/client/screen.c | 1 | ||||
-rw-r--r-- | src/common/cmd.c | 40 | ||||
-rw-r--r-- | src/refresh/images.c | 3 |
6 files changed, 25 insertions, 24 deletions
diff --git a/src/client/ascii.c b/src/client/ascii.c index 3c1cfaa..c973523 100644 --- a/src/client/ascii.c +++ b/src/client/ascii.c @@ -104,7 +104,6 @@ static void TH_DrawLayoutString(char *dst, const char *s) x = 0; y = 0; - width = 3; while (s) { token = COM_Parse(&s); diff --git a/src/client/entities.c b/src/client/entities.c index f5cdbf4..25a6b61 100644 --- a/src/client/entities.c +++ b/src/client/entities.c @@ -385,7 +385,7 @@ void CL_DeltaFrame(void) // for debugging problems when out-of-date entity origin is referenced void CL_CheckEntityPresent(int entnum, const char *what) { - centity_t *e = &cl_entities[entnum]; + centity_t *e; if (entnum == cl.frame.clientNum + 1) { return; // player entity = current diff --git a/src/client/parse.c b/src/client/parse.c index 29bc8d2..9004a15 100644 --- a/src/client/parse.c +++ b/src/client/parse.c @@ -198,7 +198,6 @@ static void CL_ParseFrame(int extrabits) cl.frameflags = 0; - suppressed = 0; extraflags = 0; if (cls.serverProtocol > PROTOCOL_VERSION_DEFAULT) { bits = MSG_ReadLong(); @@ -424,7 +423,6 @@ static void CL_ParseConfigstring(int index) Com_WPrintf( "%s: index %d overflowed: %"PRIz" > %"PRIz"\n", __func__, index, len, maxlen - 1); - len = maxlen - 1; } if (cls.demo.seeking) { diff --git a/src/client/screen.c b/src/client/screen.c index 02fcffc..ae34372 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -1471,7 +1471,6 @@ static void draw_layout_string(const char *s) x = 0; y = 0; - width = 3; while (s) { token = COM_Parse(&s); diff --git a/src/common/cmd.c b/src/common/cmd.c index 03a2836..9e1fce4 100644 --- a/src/common/cmd.c +++ b/src/common/cmd.c @@ -1046,40 +1046,42 @@ int Cmd_ParseOptions(const cmd_option_t *opt) } return -1; // special terminator } + + // check for long option argument if ((p = strchr(s, '=')) != NULL) { *p = 0; } + + // parse long option for (o = opt; o->sh; o++) { if (!strcmp(o->lo, s)) { break; } } + if (!o->sh) { + goto unknown; + } + + // parse long option argument if (p) { - if (o->sh[1] == ':') { - cmd_optarg = p + 1; - } else { - Com_Printf("%s does not take an argument.\n", o->lo); + if (o->sh[1] != ':') { + Com_Printf("%s does not take an argument.\n", cmd_argv[cmd_optind]); Cmd_PrintHint(); + return '!'; } - *p = 0; + cmd_optarg = p + 1; } } else { - p = NULL; - if (s[1]) { - goto unknown; - } + // parse short option for (o = opt; o->sh; o++) { if (o->sh[0] == *s) { break; } } - } - - if (!o->sh) { -unknown: - Com_Printf("Unknown option: %s.\n", cmd_argv[cmd_optind]); - Cmd_PrintHint(); - return '?'; + if (!o->sh || s[1]) { + goto unknown; + } + p = NULL; } // parse option argument @@ -1093,8 +1095,12 @@ unknown: } cmd_optind++; - return o->sh[0]; + +unknown: + Com_Printf("Unknown option: %s.\n", cmd_argv[cmd_optind]); + Cmd_PrintHint(); + return '?'; } void Cmd_PrintUsage(const cmd_option_t *opt, const char *suffix) diff --git a/src/refresh/images.c b/src/refresh/images.c index f012e20..4da9307 100644 --- a/src/refresh/images.c +++ b/src/refresh/images.c @@ -197,8 +197,7 @@ IMG_LOAD(WAL) return Q_ERR_INVALID_FORMAT; } - size = w * h; - size = MIPSIZE(size); + size = MIPSIZE(w * h); endpos = offset + size; if (endpos < offset || endpos > rawlen) { return Q_ERR_BAD_EXTENT; |