From 1216c9da18b1d3c7e22d7a13c1d7f98040d82e27 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 23 Feb 2018 20:21:16 +0000 Subject: [PATCH 1/2] Use __linux__ instead of LINUX/LINUX64 Turns out compiling for Linux 32-bit using the Makefiles never actually defines LINUX! Apart from that, most of the existing Linux-specific code in SRB2's source code (except for tmap.s) actually uses __linux__ instead anyway --- src/sdl/i_system.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 3ad57559d..4675ac142 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2709,7 +2709,7 @@ const char *I_LocateWad(void) return waddir; } -#if defined(LINUX) || defined(LINUX64) +#ifdef __linux__ #define MEMINFO_FILE "/proc/meminfo" #define MEMTOTAL "MemTotal:" #define MEMFREE "MemFree:" @@ -2773,7 +2773,7 @@ UINT32 I_GetFreeMem(UINT32 *total) (PVOID) &pr_arena, sizeof (UINT32)); return pr_arena; -#elif defined (LINUX) || defined (LINUX64) +#elif defined (__linux__) /* Linux */ char buf[1024]; char *memTag; @@ -2822,7 +2822,7 @@ UINT32 I_GetFreeMem(UINT32 *total) if (total) *total = 48<<20; return 48<<20; -#endif /* LINUX */ +#endif } const CPUInfoFlags *I_CPUInfo(void) From 4a0305eec8e4646d171ccc527cb706175609a3ba Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 23 Feb 2018 20:40:19 +0000 Subject: [PATCH 2/2] more I_GetFreeMem fixes: don't attempt to set *total to 0L if total itself is NULL --- src/sdl/i_system.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 4675ac142..e86a39cab 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2729,20 +2729,23 @@ UINT32 I_GetFreeMem(UINT32 *total) }; if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { - *total = 0L; + if (total) + *total = 0L; return 0; } if (kvm_nlist(kd, namelist) != 0) { kvm_close (kd); - *total = 0L; + if (total) + *total = 0L; return 0; } if (kvm_read(kd, namelist[X_SUM].n_value, &sum, sizeof (sum)) != sizeof (sum)) { kvm_close(kd); - *total = 0L; + if (total) + *total = 0L; return 0; } kvm_close(kd); @@ -2789,25 +2792,28 @@ UINT32 I_GetFreeMem(UINT32 *total) if (n < 0) { // Error - *total = 0L; + if (total) + *total = 0L; return 0; } buf[n] = '\0'; - if (NULL == (memTag = strstr(buf, MEMTOTAL))) + if ((memTag = strstr(buf, MEMTOTAL)) == NULL) { // Error - *total = 0L; + if (total) + *total = 0L; return 0; } memTag += sizeof (MEMTOTAL); totalKBytes = atoi(memTag); - if (NULL == (memTag = strstr(buf, MEMFREE))) + if ((memTag = strstr(buf, MEMFREE)) == NULL) { // Error - *total = 0L; + if (total) + *total = 0L; return 0; }