From 43131effaa913a40fe10c15836e272c484b7c4f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Mar 2023 09:49:40 +0200 Subject: [PATCH 46/51] - avoid arithmetics with literal null pointers in ParseCommandLine. Also avoid using longs. --- src/m_misc.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/m_misc.cpp b/src/m_misc.cpp index 6e40991da..45af80cec 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -74,7 +74,7 @@ CVAR(String, screenshot_type, "png", CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR(String, screenshot_dir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG); EXTERN_CVAR(Bool, longsavemessages); -static long ParseCommandLine (const char *args, int *argc, char **argv); +static size_t ParseCommandLine (const char *args, int *argc, char **argv); //--------------------------------------------------------------------------- @@ -101,7 +101,7 @@ void M_FindResponseFile (void) TArray file; int argc = 0; int size; - long argsize = 0; + size_t argsize = 0; int index; // Any more response files after the limit will be removed from the @@ -179,17 +179,19 @@ void M_FindResponseFile (void) // This is just like the version in c_dispatch.cpp, except it does not // do cvar expansion. -static long ParseCommandLine (const char *args, int *argc, char **argv) +static size_t ParseCommandLine (const char *args, int *argc, char **argv) { int count; + char* buffstart; char *buffplace; count = 0; - buffplace = NULL; + buffstart = NULL; if (argv != NULL) { - buffplace = argv[0]; + buffstart = argv[0]; } + buffplace = buffstart; for (;;) { @@ -257,7 +259,7 @@ static long ParseCommandLine (const char *args, int *argc, char **argv) { *argc = count; } - return (long)(buffplace - (char *)0); + return (buffplace - buffstart); } -- 2.39.3