shithub: choc

Download patch

ref: 9be786f9a5a7019d465eb9f11dcc143bad388579
parent: 293b22549c00c996f3c88e00365c78a4ad980b64
author: mfrancis95 <mikefrancis95@gmail.com>
date: Thu Jul 2 19:36:07 EDT 2020

When running sscanf on numbers in hex or octal, make sure the argument type is unsigned int *

This fixes warnings that were showing up in cppcheck

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1371,10 +1371,10 @@
     if (env != NULL)
     {
         char winenv[30];
-        int winid;
+        unsigned int winid;
 
         sscanf(env, "0x%x", &winid);
-        M_snprintf(winenv, sizeof(winenv), "SDL_WINDOWID=%i", winid);
+        M_snprintf(winenv, sizeof(winenv), "SDL_WINDOWID=%u", winid);
 
         putenv(winenv);
     }
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1923,7 +1923,7 @@
     int parm;
 
     if (strparm[0] == '0' && strparm[1] == 'x')
-        sscanf(strparm+2, "%x", &parm);
+        sscanf(strparm+2, "%x", (unsigned int *) &parm);
     else
         sscanf(strparm, "%i", &parm);
 
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -259,9 +259,9 @@
 
 boolean M_StrToInt(const char *str, int *result)
 {
-    return sscanf(str, " 0x%x", result) == 1
-        || sscanf(str, " 0X%x", result) == 1
-        || sscanf(str, " 0%o", result) == 1
+    return sscanf(str, " 0x%x", (unsigned int *) result) == 1
+        || sscanf(str, " 0X%x", (unsigned int *) result) == 1
+        || sscanf(str, " 0%o", (unsigned int *) result) == 1
         || sscanf(str, " %d", result) == 1;
 }