From baeb343164039cc4124ef53dfa7f386cdb43b5d2 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:05:12 +0200 Subject: [PATCH] Improve pad removal of CPU brand identifier Reverse scan CPU brand name until first non space character is found. --- r5dev/tier0/cpu.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/r5dev/tier0/cpu.cpp b/r5dev/tier0/cpu.cpp index 0b45d0c8..0de142c8 100644 --- a/r5dev/tier0/cpu.cpp +++ b/r5dev/tier0/cpu.cpp @@ -298,13 +298,17 @@ const char* GetProcessorBrand(bool bRemovePadding = true) if (bRemovePadding) { - for (int i = 0; i < sizeof(s_CpuBrand.name) - 1; i++) + for (size_t i = sizeof(s_CpuBrand.name); i-- > 0; ) { - if (s_CpuBrand.name[i] == ' ') + if (s_CpuBrand.name[i] != '\0') { - if (s_CpuBrand.name[i + 1] == ' ') + if (s_CpuBrand.name[i] != ' ') { - s_CpuBrand.name[i] = '\0'; + if (i < (sizeof(s_CpuBrand.name) - 1)) + { + s_CpuBrand.name[i + 1] = '\0'; + break; + } } } }