Maximilian Stein has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/45185 )

Change subject: arch-x86: Fix build after merging #42824
......................................................................

arch-x86: Fix build after merging #42824

Caused by std::strncpy and -Werror=stringop-truncation.

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



diff --git a/src/arch/x86/bios/acpi.cc b/src/arch/x86/bios/acpi.cc
index 53b6e4d..6ae94b0 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>

@@ -93,7 +94,8 @@
     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));
+    std::memcpy(data->oemID, params().oem_id.c_str(),
+            std::min(sizeof(data->oemID), params().oem_id.length()));
     data->revision = params().revision;
     data->length = mem.size();

@@ -133,12 +135,14 @@
     // Fill in the header.
     auto& p = params();
     Mem* header = (Mem*)mem.data();
-    std::strncpy(header->signature, signature, sizeof(header->signature));
+    std::memcpy(header->signature, signature,
+            std::min(sizeof(header->signature), std::strlen(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));
+    std::memcpy(header->oemID, p.oem_id.c_str(),
+            std::min(sizeof(header->oemID), p.oem_id.length()));
+    std::memcpy(header->oemTableID, p.oem_table_id.c_str(),
+            std::min(sizeof(header->oemTableID), p.oem_table_id.length()));
     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/+/45185
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: Ib05f267e0a385e186b44e9fad96541009e545fdc
Gerrit-Change-Number: 45185
Gerrit-PatchSet: 1
Gerrit-Owner: Maximilian Stein <m...@steiny.biz>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to