From 7039662eeba5ba6ff56b258a0a25236a8a4f0c83 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 17 Nov 2020 21:45:55 -0800 Subject: [PATCH] x86: Fix object scope in the CPUID code. The original version of the code takes a pointer from a temporary object which gets destroyed before the pointer is used. Change-Id: I16af4eefdf202f769a672e230330d8e0bfce3bb7 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/37695 Reviewed-by: Matthew Poremba Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/arch/x86/cpuid.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/arch/x86/cpuid.cc b/src/arch/x86/cpuid.cc index 8c9f29cef..2a560f510 100644 --- a/src/arch/x86/cpuid.cc +++ b/src/arch/x86/cpuid.cc @@ -94,12 +94,12 @@ namespace X86ISA { case VendorAndLargestExtFunc: { ISA *isa = dynamic_cast(tc->getIsaPtr()); - const char *vendor_string = isa->getVendorString().c_str(); + auto vendor_string = isa->getVendorString(); result = CpuidResult( 0x80000000 + NumExtendedCpuidFuncs - 1, - stringToRegister(vendor_string), - stringToRegister(vendor_string + 4), - stringToRegister(vendor_string + 8)); + stringToRegister(vendor_string.c_str()), + stringToRegister(vendor_string.c_str() + 4), + stringToRegister(vendor_string.c_str() + 8)); } break; case FamilyModelSteppingBrandFeatures: @@ -155,12 +155,12 @@ namespace X86ISA { case VendorAndLargestStdFunc: { ISA *isa = dynamic_cast(tc->getIsaPtr()); - const char *vendor_string = isa->getVendorString().c_str(); + auto vendor_string = isa->getVendorString(); result = CpuidResult( NumExtendedCpuidFuncs - 1, - stringToRegister(vendor_string), - stringToRegister(vendor_string + 4), - stringToRegister(vendor_string + 8)); + stringToRegister(vendor_string.c_str()), + stringToRegister(vendor_string.c_str() + 4), + stringToRegister(vendor_string.c_str() + 8)); } break; case FamilyModelStepping: -- 2.30.2