Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/45205 )

Change subject: arch-x86: Fix x86 build.
......................................................................

arch-x86: Fix x86 build.

Variation of fix by Maximilian Stein:

https://gem5-review.googlesource.com/c/public/gem5/+/45185

Placate gcc, which thinks we're doing something wrong when using
strncpy. Also ensure that fixed size buffers for strings are filled
completely, rather than just filling in the part which holds the string
we want.

Change-Id: I59f51f6a56a3a3e2632eb89ecb6db709fbbd165d
---
M src/arch/x86/bios/acpi.cc
1 file changed, 25 insertions(+), 5 deletions(-)



diff --git a/src/arch/x86/bios/acpi.cc b/src/arch/x86/bios/acpi.cc
index 53b6e4d..9a5d32e 100644
--- a/src/arch/x86/bios/acpi.cc
+++ b/src/arch/x86/bios/acpi.cc
@@ -37,6 +37,7 @@

 #include "arch/x86/bios/acpi.hh"

+#include <algorithm>
 #include <cassert>
 #include <cstring>

@@ -52,6 +53,26 @@
 namespace ACPI
 {

+static void
+fillCopy(void *dest, size_t dest_size, const void *src, size_t src_size)
+{
+    src_size = std::min(src_size, dest_size);
+    const size_t zero_size = dest_size - src_size;
+
+    uint8_t *pos = (uint8_t *)dest;
+
+    std::memcpy(pos, src, src_size);
+    pos += src_size;
+
+    std::memset(pos, 0, zero_size);
+}
+
+static void
+fillCopy(void *dest, size_t dest_size, const std::string &src)
+{
+    fillCopy(dest, dest_size, src.c_str(), src.length());
+}
+
 const char RSDP::signature[] = "RSD PTR ";

 static uint8_t
@@ -93,7 +114,7 @@
     static_assert(sizeof(signature) - 1 == sizeof(data->signature),
             "signature length mismatch");
     std::memcpy(data->signature, signature, sizeof(data->signature));
- std::strncpy(data->oemID, params().oem_id.c_str(), sizeof(data->oemID));
+    fillCopy(data->oemID, sizeof(data->oemID), params().oem_id);
     data->revision = params().revision;
     data->length = mem.size();

@@ -133,12 +154,11 @@
     // Fill in the header.
     auto& p = params();
     Mem* header = (Mem*)mem.data();
-    std::strncpy(header->signature, signature, sizeof(header->signature));
+    fillCopy(header->signature, sizeof(header->signature), signature);
     header->length = mem.size();
     header->revision = revision;
-    std::strncpy(header->oemID, p.oem_id.c_str(), sizeof(header->oemID));
-    std::strncpy(header->oemTableID, p.oem_table_id.c_str(),
-            sizeof(header->oemTableID));
+    fillCopy(header->oemID, sizeof(header->oemID), p.oem_id);
+ fillCopy(header->oemTableID, sizeof(header->oemTableID), p.oem_table_id);
     header->oemRevision = p.oem_revision;
     header->creatorID = p.creator_id;
     header->creatorRevision = p.creator_revision;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45205
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I59f51f6a56a3a3e2632eb89ecb6db709fbbd165d
Gerrit-Change-Number: 45205
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to