Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f2e964f authored by Sharjeel Khan's avatar Sharjeel Khan
Browse files

Fix -Wnontrivial-memcall warning

Memcall functions work at the byte level so they don't know about C++
semantics and these C++ objects might not have trivial
constructors or destructors. I silenced the warning by explicitly
casting the pointer to void* with static_cast. I did this fix because I
assume the code developer knows the consequences with using memcall
functions with C++ objects.

frameworks/base/tools/bit/util.cpp:28:12: error: first argument in call
to 'memset' is a pointer to non-trivially copyable type 'FileInfo'
[-Werror,-Wnontrivial-memcall]
   28 |     memset(this, 0, sizeof(FileInfo));
      |            ^

frameworks/base/tools/bit/util.cpp:33:12: error: first argument in call
to 'memcpy' is a pointer to non-trivially copyable type 'FileInfo'
[-Werror,-Wnontrivial-memcall]
   33 |     memcpy(this, &that, sizeof(FileInfo));
      |            ^

frameworks/base/tools/bit/util.cpp:41:16: error: first argument in call
to 'memset' is a pointer to non-trivially copyable type 'FileInfo'
[-Werror,-Wnontrivial-memcall]
   41 |         memset(this, 0, sizeof(FileInfo));
      |                ^

Flag: EXEMPT warning fix
Bug: 430598176
Test: m && presubmits
Change-Id: I3620b46ecf194719f12169e23735b73b0717d9a1
parent e22d9d10
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@

FileInfo::FileInfo()
{
    memset(this, 0, sizeof(FileInfo));
    memset(static_cast<void*>(this), 0, sizeof(FileInfo));
}

FileInfo::FileInfo(const FileInfo& that)
{
    memcpy(this, &that, sizeof(FileInfo));
    memcpy(static_cast<void*>(this), &that, sizeof(FileInfo));
}

FileInfo::FileInfo(const string& filename)
@@ -38,7 +38,7 @@ FileInfo::FileInfo(const string& filename)
    struct stat st;
    int err = stat(filename.c_str(), &st);
    if (err != 0) {
        memset(this, 0, sizeof(FileInfo));
        memset(static_cast<void*>(this), 0, sizeof(FileInfo));
    } else {
        exists = true;
        mtime = st.st_mtime;