From d3c1de5f401fbd94668b5d620d033095f208fd2d Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Mon, 7 Mar 2011 17:09:26 +0000 Subject: [PATCH] Work-around for possible q3lcc/q3asm bug ([unsigned] int to unsigned short conversion) --- reaction/code/ui/ui_main.c | 24 ++++++++++-------------- reaction/code/ui/ui_shared.h | 3 ++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/reaction/code/ui/ui_main.c b/reaction/code/ui/ui_main.c index cdd54b48..1e8ccf87 100644 --- a/reaction/code/ui/ui_main.c +++ b/reaction/code/ui/ui_main.c @@ -5798,24 +5798,21 @@ static void UI_Update(const char *name) } } -static qboolean UI_ParseResolution(char* str, int* width, int* height) +static qboolean UI_ParseResolution(char* str, resolution_t* res) { char* x = strchr(str, 'x'); if (!x) { - *width = *height = 0; + res->width = res->height = 0; return qfalse; } *x++ = 0; - if (1 != sscanf(str, "%d", width) || 1 != sscanf(x, "%d", height)) - { - *width = *height = 0; - return qfalse; - } + res->width = atoi(str); + res->height = atoi(x); - return qtrue; + return res->width > 0 && res->height > 0; } static void UI_SelectCurrentResolution() @@ -5852,17 +5849,16 @@ static void UI_GetSupportedModes() for (tok=strtok(buf, delim); tok; tok=strtok(NULL, delim)) { - int width, height; - if (UI_ParseResolution(tok, &width, &height)) + resolution_t tmp; + if (UI_ParseResolution(tok, &tmp)) { idx = uiInfo.uiDC.numSupportedModes++; - if (uiInfo.uiDC.numSupportedModes > MAX_NUM_SUPPORTED_MODES) + if (uiInfo.uiDC.numSupportedModes == MAX_NUM_SUPPORTED_MODES) { Com_Printf(S_COLOR_YELLOW "Warning: more than MAX_NUM_SUPPORTED_MODES resolutions found.\n"); - return; + break; } - uiInfo.uiDC.supportedMode[idx].width = width; - uiInfo.uiDC.supportedMode[idx].height = height; + uiInfo.uiDC.supportedMode[idx] = tmp; } } diff --git a/reaction/code/ui/ui_shared.h b/reaction/code/ui/ui_shared.h index e6c2fb85..20585245 100644 --- a/reaction/code/ui/ui_shared.h +++ b/reaction/code/ui/ui_shared.h @@ -507,7 +507,8 @@ typedef struct { #define MAX_NUM_SUPPORTED_MODES 256 typedef struct { - unsigned short width, height; + unsigned int width; + unsigned int height; } resolution_t; typedef struct {