cpuid/x86: null terminate strings for convenience

This commit is contained in:
Danny Robson 2019-06-20 14:42:17 +10:00
parent 3b5ec78513
commit 4edd8d8c3e
2 changed files with 4 additions and 2 deletions

View File

@ -45,6 +45,7 @@ x86::x86 ()
memcpy (vendor_name.data () + 0, &vendor0, sizeof (vendor0)); memcpy (vendor_name.data () + 0, &vendor0, sizeof (vendor0));
memcpy (vendor_name.data () + 4, &vendor1, sizeof (vendor1)); memcpy (vendor_name.data () + 4, &vendor1, sizeof (vendor1));
memcpy (vendor_name.data () + 8, &vendor2, sizeof (vendor2)); memcpy (vendor_name.data () + 8, &vendor2, sizeof (vendor2));
vendor_name.back () = '\0';
const bool is_amd = vendor0 == 0x68747541 && vendor1 == 0x69746e65 && vendor2 == 0x444d4163; const bool is_amd = vendor0 == 0x68747541 && vendor1 == 0x69746e65 && vendor2 == 0x444d4163;
@ -71,6 +72,7 @@ x86::x86 ()
memcpy (&product_name[0x00], &product0, sizeof (product0)); memcpy (&product_name[0x00], &product0, sizeof (product0));
memcpy (&product_name[0x10], &product1, sizeof (product1)); memcpy (&product_name[0x10], &product1, sizeof (product1));
memcpy (&product_name[0x20], &product2, sizeof (product2)); memcpy (&product_name[0x20], &product2, sizeof (product2));
product_name.back () = '\0';
} }
// Function 4 isn't implemented by AMD. Intel uses it for cache // Function 4 isn't implemented by AMD. Intel uses it for cache

View File

@ -41,8 +41,8 @@ namespace cruft::cpu {
bool avx; bool avx;
} simd; } simd;
std::array<char,12> vendor_name; std::array<char,12+1> vendor_name;
std::array<char,48> product_name; std::array<char,48+1> product_name;
}; };
std::ostream& std::ostream&