From 312b23522ad8fa76bc6a79cd87e2b327635edb77 Mon Sep 17 00:00:00 2001 From: Ryan Salsamendi Date: Sat, 1 Jul 2017 18:21:46 -0700 Subject: cpu/x86/name: Fix undefined behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes report found by undefined behavior sanitizer. Dereferencing a pointer that's not aligned to the size of access is undefined behavior. Remove unnecessary memset(). Change-Id: I1362a3eb8c97f5c7e848d75f8d1a219968a7ef9e Signed-off-by: Ryan Salsamendi Reviewed-on: https://review.coreboot.org/20452 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Philippe Mathieu-Daudé --- src/cpu/x86/name/name.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/cpu/x86') diff --git a/src/cpu/x86/name/name.c b/src/cpu/x86/name/name.c index b59fd8bef9..cff2e5c6ad 100644 --- a/src/cpu/x86/name/name.c +++ b/src/cpu/x86/name/name.c @@ -21,9 +21,8 @@ void fill_processor_name(char *processor_name) { struct cpuid_result regs; - char temp_processor_name[49]; char *processor_name_start; - unsigned int *name_as_ints = (unsigned int *)temp_processor_name; + uint32_t name_as_ints[13]; int i; for (i = 0; i < 3; i++) { @@ -34,13 +33,12 @@ void fill_processor_name(char *processor_name) name_as_ints[i * 4 + 3] = regs.edx; } - temp_processor_name[48] = 0; + name_as_ints[12] = 0; /* Skip leading spaces. */ - processor_name_start = temp_processor_name; + processor_name_start = (char *)name_as_ints; while (*processor_name_start == ' ') processor_name_start++; - memset(processor_name, 0, 49); strcpy(processor_name, processor_name_start); } -- cgit v1.2.3