summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Figuière <hub@figuiere.net>2022-02-14 10:38:48 -0500
committerHubert Figuière <hub@figuiere.net>2022-02-14 10:38:48 -0500
commit9ab742ccca92a6c65133cd28aee4764ba7fcf12a (patch)
treea00648bf8872e0be1aa3b821ac4a82994b29a820
parent0ac0675dcd41cf44dfee36216e032bcc46cfd9f3 (diff)
Fix several -Wclass-memaccess warnings
- XmpDate and BoxInfo have constructors
-rw-r--r--XMPCore/source/XMPUtils.cpp4
-rw-r--r--XMPFiles/source/FileHandlers/MPEG4_Handler.cpp10
-rw-r--r--XMPFiles/source/FileHandlers/Scanner_Handler.cpp3
-rw-r--r--XMPFiles/source/FormatSupport/ASF_Support.cpp3
-rw-r--r--XMPFiles/source/FormatSupport/ISOBaseMedia_Support.cpp12
-rw-r--r--XMPFiles/source/FormatSupport/META_Support.cpp6
-rw-r--r--XMPFiles/source/FormatSupport/MOOV_Support.cpp6
-rw-r--r--XMPFiles/source/FormatSupport/ReconcileIPTC.cpp3
-rw-r--r--samples/source/common/DumpFile.cpp15
9 files changed, 47 insertions, 15 deletions
diff --git a/XMPCore/source/XMPUtils.cpp b/XMPCore/source/XMPUtils.cpp
index 609eee3..85524d4 100644
--- a/XMPCore/source/XMPUtils.cpp
+++ b/XMPCore/source/XMPUtils.cpp
@@ -2479,7 +2479,9 @@ XMPUtils::ConvertToDate ( XMP_StringPtr strValue,
XMP_Int32 temp;
XMP_Assert ( sizeof(*binValue) == sizeof(XMP_DateTime) );
- (void) memset ( binValue, 0, sizeof(*binValue) ); // AUDIT: Safe, using sizeof destination.
+ // (Exempi) UNSAFE. You don't memset a C++ object.
+ *binValue = XMP_DateTime();
+ //(void) memset ( binValue, 0, sizeof(*binValue) ); // AUDIT: Safe, using sizeof destination.
size_t strSize = strlen ( strValue );
bool timeOnly = ( (strValue[0] == 'T') ||
diff --git a/XMPFiles/source/FileHandlers/MPEG4_Handler.cpp b/XMPFiles/source/FileHandlers/MPEG4_Handler.cpp
index 394bcb0..f0f58c1 100644
--- a/XMPFiles/source/FileHandlers/MPEG4_Handler.cpp
+++ b/XMPFiles/source/FileHandlers/MPEG4_Handler.cpp
@@ -350,7 +350,9 @@ MPEG4_MetaHandler::~MPEG4_MetaHandler()
static void SecondsToXMPDate ( XMP_Uns64 isoSeconds, XMP_DateTime * xmpDate )
{
- memset ( xmpDate, 0, sizeof(XMP_DateTime) ); // AUDIT: Using sizeof(XMP_DateTime) is safe.
+ // (Exempi) UNSAFE. You don't memset a C++ object.
+ *xmpDate = XMP_DateTime();
+ // memset ( xmpDate, 0, sizeof(XMP_DateTime) ); // AUDIT: Using sizeof(XMP_DateTime) is safe.
XMP_Int32 days = (XMP_Int32) (isoSeconds / 86400);
isoSeconds -= ((XMP_Uns64)days * 86400);
@@ -1886,8 +1888,10 @@ static void CheckFinalBox ( XMP_IO* fileRef, XMP_AbortProc abortProc, void * abo
ISOMedia::BoxInfo prevBox, lastBox;
XMP_Uns8 buffer [16]; // Enough to create an extended header.
- memset ( &prevBox, 0, sizeof(prevBox) ); // AUDIT: Using sizeof(prevBox) is safe.
- memset ( &lastBox, 0, sizeof(lastBox) ); // AUDIT: Using sizeof(lastBox) is safe.
+ // (Exempi) UNSAFE. You don't memset a C++ object.
+ // (Exempi) Here the constructor is already called.
+ //memset ( &prevBox, 0, sizeof(prevBox) ); // AUDIT: Using sizeof(prevBox) is safe.
+ //memset ( &lastBox, 0, sizeof(lastBox) ); // AUDIT: Using sizeof(lastBox) is safe.
prevPos = lastPos = nextPos = 0;
while ( nextPos != fileSize ) {
if ( checkAbort && abortProc(abortArg) ) {
diff --git a/XMPFiles/source/FileHandlers/Scanner_Handler.cpp b/XMPFiles/source/FileHandlers/Scanner_Handler.cpp
index 6f9b46b..6ad1370 100644
--- a/XMPFiles/source/FileHandlers/Scanner_Handler.cpp
+++ b/XMPFiles/source/FileHandlers/Scanner_Handler.cpp
@@ -164,7 +164,8 @@ PickMainPacket ( std::vector<CandidateInfo>& candidates, bool beLenient )
if ( ! beLenient ) return -1;
if ( main == -1 ) {
main = pkt;
- memset ( &latestTime, 0, sizeof(latestTime) );
+ // (Exempi) Unsafe, constructor is already called
+ //memset ( &latestTime, 0, sizeof(latestTime) );
}
} else if ( main == -1 ) {
diff --git a/XMPFiles/source/FormatSupport/ASF_Support.cpp b/XMPFiles/source/FormatSupport/ASF_Support.cpp
index 0a17791..cc11cf4 100644
--- a/XMPFiles/source/FormatSupport/ASF_Support.cpp
+++ b/XMPFiles/source/FormatSupport/ASF_Support.cpp
@@ -1396,7 +1396,8 @@ void ASF_LegacyManager::ConvertMSDateToISODate ( std::string& source, std::strin
// A little more simple code converts this to an XMP date string:
XMP_DateTime date;
- memset ( &date, 0, sizeof ( date ) );
+ // (Exempi) Unsafe to memset, constructor called
+ // memset ( &date, 0, sizeof ( date ) );
date.year = 1601; // The MS date origin.
date.month = 1;
diff --git a/XMPFiles/source/FormatSupport/ISOBaseMedia_Support.cpp b/XMPFiles/source/FormatSupport/ISOBaseMedia_Support.cpp
index b0945cb..611d10f 100644
--- a/XMPFiles/source/FormatSupport/ISOBaseMedia_Support.cpp
+++ b/XMPFiles/source/FormatSupport/ISOBaseMedia_Support.cpp
@@ -251,7 +251,11 @@ ISOBaseMedia_Manager::BoxRef ISOBaseMedia_Manager::GetNthChild(BoxRef parentRef,
{
XMP_Assert(parentRef != 0);
const BoxNode & parent = *((BoxNode*)parentRef);
- if (info != 0) memset(info, 0, sizeof(BoxInfo));
+ if (info != 0) {
+ // (Exempi) Unsafe to memset()
+ *info = BoxInfo();
+ //memset(info, 0, sizeof(BoxInfo));
+ }
if (childIndex >= parent.children.size()) return 0;
@@ -269,7 +273,11 @@ ISOBaseMedia_Manager::BoxRef ISOBaseMedia_Manager::GetTypeChild(BoxRef parentRef
{
XMP_Assert(parentRef != 0);
const BoxNode & parent = *((BoxNode*)parentRef);
- if (info != 0) memset(info, 0, sizeof(BoxInfo));
+ if (info != 0) {
+ // (Exempi) Unsafe to memset()
+ *info = BoxInfo();
+ //memset(info, 0, sizeof(BoxInfo));
+ }
if (parent.children.empty()) return 0;
size_t i = 0, limit = parent.children.size();
diff --git a/XMPFiles/source/FormatSupport/META_Support.cpp b/XMPFiles/source/FormatSupport/META_Support.cpp
index 281b9a8..8ef12cd 100644
--- a/XMPFiles/source/FormatSupport/META_Support.cpp
+++ b/XMPFiles/source/FormatSupport/META_Support.cpp
@@ -114,7 +114,11 @@ ISOBaseMedia_Manager::BoxRef Meta_Manager::GetBox(const char * boxPath, BoxInfo
{
size_t pathLen = strlen(boxPath);
XMP_Assert((pathLen >= 4) && XMP_LitNMatch(boxPath, "meta", 4));
- if (info != 0) memset(info, 0, sizeof(BoxInfo));
+ if (info != 0) {
+ // (Exempi) Unsafe to memset
+ *info = BoxInfo();
+ //memset(info, 0, sizeof(BoxInfo));
+ }
const char * pathPtr = boxPath + 5; // Skip the "meta/" portion.
const char * pathEnd = boxPath + pathLen;
diff --git a/XMPFiles/source/FormatSupport/MOOV_Support.cpp b/XMPFiles/source/FormatSupport/MOOV_Support.cpp
index fc52457..a0292ed 100644
--- a/XMPFiles/source/FormatSupport/MOOV_Support.cpp
+++ b/XMPFiles/source/FormatSupport/MOOV_Support.cpp
@@ -44,7 +44,11 @@ MOOV_Manager::BoxRef MOOV_Manager::GetBox ( const char * boxPath, BoxInfo * info
{
size_t pathLen = strlen(boxPath);
XMP_Assert ( (pathLen >= 4) && XMP_LitNMatch ( boxPath, "moov", 4 ) );
- if ( info != 0 ) memset ( info, 0, sizeof(BoxInfo) );
+ if ( info != 0 ) {
+ // (Exempi) Unsafe to memset
+ *info = BoxInfo();
+ //memset ( info, 0, sizeof(BoxInfo) );
+ }
const char * pathPtr = boxPath + 5; // Skip the "moov/" portion.
const char * pathEnd = boxPath + pathLen;
diff --git a/XMPFiles/source/FormatSupport/ReconcileIPTC.cpp b/XMPFiles/source/FormatSupport/ReconcileIPTC.cpp
index bf797d5..5bead01 100644
--- a/XMPFiles/source/FormatSupport/ReconcileIPTC.cpp
+++ b/XMPFiles/source/FormatSupport/ReconcileIPTC.cpp
@@ -197,7 +197,8 @@ void PhotoDataUtils::ImportIPTC_Date ( XMP_Uns8 dateID, const IPTC_Manager & ipt
size_t chPos, digits;
XMP_DateTime xmpDate;
- memset ( &xmpDate, 0, sizeof(xmpDate) );
+ // (Exempi) unsafe. Constructor is already called
+ //memset ( &xmpDate, 0, sizeof(xmpDate) );
chPos = 0;
for ( digits = 0; digits < 4; ++digits, ++chPos ) {
diff --git a/samples/source/common/DumpFile.cpp b/samples/source/common/DumpFile.cpp
index e3d8888..eef46b4 100644
--- a/samples/source/common/DumpFile.cpp
+++ b/samples/source/common/DumpFile.cpp
@@ -530,7 +530,12 @@ struct ASF_GUID {
XMP_Uns16 part4; // Written big endian.
XMP_Uns8 part5[6]; // Written in order.
- ASF_GUID() {};
+ // (Exempi) needs a proper constructor
+ ASF_GUID()
+ : part1(0), part2(0), part3(0), part4(0),
+ part5({ 0, 0, 0, 0, 0, 0 })
+ {
+ }
ASF_GUID(XMP_Uns32 p1, XMP_Uns16 p2, XMP_Uns16 p3, XMP_Uns16 p4, const void* p5)
{
part1 = GetUns32LE(&p1);
@@ -538,7 +543,7 @@ struct ASF_GUID {
part3 = GetUns16LE(&p3);
part4 = GetUns16BE(&p4);
memcpy(&part5, p5, 6);
- };
+ }
};
@@ -3133,7 +3138,8 @@ static size_t GetASFObjectInfo(LFA_FileRef file, XMP_Uns32 objOffset, ASF_ObjHea
tree->addComment("%s <<unknown object>>, offset %u (0x%X), size %u",
indent.c_str(), objOffset, objOffset, size32);
ASF_GUID guid;
- memset(&guid, 0, sizeof(ASF_GUID));
+ // (Exempi) memset is unsafe, constructor is called)
+ // memset(&guid, 0, sizeof(ASF_GUID));
guid.part1 = GetUns32LE(&objHeader->guid.part1);
guid.part2 = GetUns16LE(&objHeader->guid.part2);
guid.part3 = GetUns16LE(&objHeader->guid.part3);
@@ -3194,7 +3200,8 @@ static void DumpASFFileProperties(LFA_FileRef file, XMP_Uns32 objOffset, XMP_Uns
totalSecs -= ((XMP_Int64)minute * 60);
XMP_Int32 second = (XMP_Int32)totalSecs;
XMP_DateTime binDate;
- memset(&binDate, 0, sizeof(binDate));
+ // (Exempi) memset is unsafe. Constructor has been called.
+ // memset(&binDate, 0, sizeof(binDate));
binDate.year = 1601;
binDate.month = 1;