x86: Fix object scope in the CPUID code.
authorGabe Black <gabe.black@gmail.com>
Wed, 18 Nov 2020 05:45:55 +0000 (21:45 -0800)
committerGabe Black <gabe.black@gmail.com>
Thu, 19 Nov 2020 01:40:30 +0000 (01:40 +0000)
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 <matthew.poremba@amd.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/x86/cpuid.cc

index 8c9f29cef9c42cecc0f71d7714cfb0d33aad25f5..2a560f510a76e52b8ed006a3755764cc920f5ae4 100644 (file)
@@ -94,12 +94,12 @@ namespace X86ISA {
               case VendorAndLargestExtFunc:
                 {
                   ISA *isa = dynamic_cast<ISA *>(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<ISA *>(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: