From: divverent Date: Wed, 5 Aug 2009 13:04:50 +0000 (+0000) Subject: add bounds check to menu function to query resolutions X-Git-Tag: xonotic-v0.1.0preview~1539 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6e5faf7bf68cf4e080039c012390f584a065f035;p=xonotic%2Fdarkplaces.git add bounds check to menu function to query resolutions git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9090 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/mvm_cmds.c b/mvm_cmds.c index f5976ac6..876deaec 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -227,10 +227,18 @@ void VM_M_getresolution(void) nr = (int)PRVM_G_FLOAT(OFS_PARM0); - // FIXME bounds check - PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width; - PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height; - PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + if(nr < 0 || nr >= video_resolutions_count) + { + PRVM_G_VECTOR(OFS_RETURN)[0] = 0; + PRVM_G_VECTOR(OFS_RETURN)[1] = 0; + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + } + else + { + PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width; + PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height; + PRVM_G_VECTOR(OFS_RETURN)[2] = 0; + } } /* diff --git a/vid_shared.c b/vid_shared.c index daf9b045..ce164b4d 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -1267,7 +1267,7 @@ void VID_Start(void) VID_OpenSystems(); } -int VID_SortModes_Compare(void *a_, void *b_) +int VID_SortModes_Compare(const void *a_, const void *b_) { vid_mode_t *a = (vid_mode_t *) a_; vid_mode_t *b = (vid_mode_t *) b_; @@ -1297,26 +1297,31 @@ size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean { size_t i; if(count == 0) - return; + return 0; // 1. sort them qsort(modes, count, sizeof(*modes), VID_SortModes_Compare); // 2. remove duplicates - for(i = 1; i < count; ++i) + for(i = 0; i < count; ++i) { - if(modes[i].width != modes[i-1].width) - continue; - if(modes[i].height != modes[i-1].height) - continue; - if(userefreshrate) - if(modes[i].refreshrate != modes[i-1].refreshrate) + if(modes[i].width && modes[i].height) + { + if(i == 0) continue; - if(usebpp) - if(modes[i].bpp != modes[i-1].bpp) + if(modes[i].width != modes[i-1].width) continue; - if(useaspect) - if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num) + if(modes[i].height != modes[i-1].height) continue; - // a dupe! + if(userefreshrate) + if(modes[i].refreshrate != modes[i-1].refreshrate) + continue; + if(usebpp) + if(modes[i].bpp != modes[i-1].bpp) + continue; + if(useaspect) + if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num) + continue; + } + // a dupe, or a bogus mode! if(i < count-1) memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i)); --i; // check this index again, as mode i+1 is now here