]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
be explicit about sizeof(T)
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 17 Mar 2023 10:23:43 +0000 (11:23 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 17 Mar 2023 10:23:45 +0000 (11:23 +0100)
ext/lmdb-safe/lmdb-safe.hh

index 1213f05cc0245bafdab1bd25a9f33e7cdfc8147e..45feac1915c32585f65003888b2028c1fd464f53 100644 (file)
@@ -177,6 +177,8 @@ struct MDBOutVal
     size_t offset = LMDBLS::LScheckHeaderAndGetSize(this, sizeof(T));
 
     memcpy(&ret, (char *)d_mdbval.mv_data+offset, sizeof(T));
+
+    static_assert(sizeof(T) == 4, "this code currently only supports 32 bit integers");
     ret = ntohl(ret);
     return ret;
   }
@@ -191,6 +193,8 @@ struct MDBOutVal
       throw std::runtime_error("MDB data has wrong length for type");
 
     memcpy(&ret, d_mdbval.mv_data, sizeof(T));
+
+    static_assert(sizeof(T) == 4, "this code currently only supports 32 bit integers");
     ret = ntohl(ret);
     return ret;
   }
@@ -273,6 +277,7 @@ public:
                                     T>::type* = nullptr>
   MDBInVal(T i)
   {
+    static_assert(sizeof(T) == 4, "this code currently only supports 32 bit integers");
     auto j = htonl(i);    // all actual usage in our codebase is 32 bits. If that ever changes, this will break the build and avoid runtime surprises
     memcpy(&d_memory[0], &j, sizeof(j));