clang-tidy: Fix packed member address warning
The following error was reported during clang-tidy enablement due to
taking the address of a packed member
'''
../apphandler.cpp:637:31:
error: taking address of packed member 'recordID' of class or structure 'ipmi::sel::SELEventRecord' may result in an unaligned pointer value [-Werror]
'''
Fix is to Copy the packed member to a temporary variable before using
its address. This ensures proper alignment.
Tested: Build and unit testing verified.
Change-Id: Ib547c1764ec4402a18851b8130f06e60cb66dae3
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 8abd5c1..f846ccd 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -21,6 +21,7 @@
#include <algorithm>
#include <chrono>
+#include <cstdint>
#include <cstdio>
#include <cstring>
#include <filesystem>
@@ -378,9 +379,11 @@
std::memcpy(response, &record.nextRecordID,
sizeof(record.nextRecordID));
+ auto tempRecordID = htole16(record.event.eventRecord.recordID);
std::memcpy(static_cast<uint8_t*>(response) +
sizeof(record.nextRecordID),
- &record.event.eventRecord.recordID + requestData->offset,
+ reinterpret_cast<const uint8_t*>(&tempRecordID) +
+ requestData->offset,
readLength);
*data_len = sizeof(record.nextRecordID) + readLength;
}