From eeea08cfa6f19b79d94d5b419290b7c51a01d7cf Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 14 Mar 2016 00:07:52 +0000 Subject: [PATCH] Fix a bug where cvars of type CVAR_UINT couldn't be set to values larger than a signed int due to clamping by atoi/atol. git-svn-id: https://svn.eduke32.com/eduke32@5666 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/osd.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index 03db5b9fb..bfc762b12 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -2097,19 +2097,18 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) } break; case CVAR_INT: - case CVAR_UINT: case CVAR_BOOL: { if (showval) { - OSD_Printf((osd->cvars[i].c.type & CVAR_UINT) ? "\"%s\" is \"%u\"\n%s: %s\n" : "\"%s\" is \"%d\"\n%s: %s\n",osd->cvars[i].c.name,*(int32_t *)osd->cvars[i].c.vptr,osd->cvars[i].c.name,osd->cvars[i].c.desc); + OSD_Printf("\"%s\" is \"%d\"\n%s: %s\n",osd->cvars[i].c.name,*(int32_t *)osd->cvars[i].c.vptr,osd->cvars[i].c.name,osd->cvars[i].c.desc); return OSDCMD_OK; } int32_t val = Batoi(parm->parms[0]); if (osd->cvars[i].c.type & CVAR_BOOL) val = val != 0; - if (val < osd->cvars[i].c.min || ((osd->cvars[i].c.type & CVAR_UINT) ? ((unsigned) val > (unsigned) osd->cvars[i].c.max) : (val > osd->cvars[i].c.max))) + if (val < osd->cvars[i].c.min || ((val > osd->cvars[i].c.max))) { OSD_Printf("%s value out of range\n",osd->cvars[i].c.name); return OSDCMD_OK; @@ -2119,6 +2118,28 @@ int32_t osdcmd_cvar_set(const osdfuncparm_t *parm) OSD_Printf("%s %d",osd->cvars[i].c.name,val); } break; + case CVAR_UINT: + { + if (showval) + { + OSD_Printf("\"%s\" is \"%u\"\n%s: %s\n", osd->cvars[i].c.name, *(int32_t *) osd->cvars[i].c.vptr, osd->cvars[i].c.name, osd->cvars[i].c.desc); + return OSDCMD_OK; + } + + uint32_t val = Bstrtoul(parm->parms[0], NULL, 0); + + if (val < (unsigned)osd->cvars[i].c.min || val > (unsigned)osd->cvars[i].c.max) + { + OSD_Printf("%s value out of range\n", osd->cvars[i].c.name); + return OSDCMD_OK; + } + + *(uint32_t *) osd->cvars[i].c.vptr = val; + + if (!OSD_ParsingScript()) + OSD_Printf("%s %d", osd->cvars[i].c.name, val); + } + break; case CVAR_STRING: { if (showval)