serialize: use a temporary for SerializeException
authorLoïc Blot <loic.blot@unix-experience.fr>
Mon, 21 Aug 2017 14:07:39 +0000 (16:07 +0200)
committerLoïc Blot <loic.blot@unix-experience.fr>
Mon, 21 Aug 2017 14:07:39 +0000 (16:07 +0200)
Exception must always use temporary instead of global copied exception instances, it's not recommended and should have undefined issues

src/util/serialize.cpp
src/util/serialize.h

index 49db9cf853558d915385ccf2cae348fcb2877ac3..a272d82eeea536b1964f66dc8480eaa659edaa8f 100644 (file)
@@ -28,8 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <iomanip>
 #include <vector>
 
-SerializationError eof_ser_err("Attempted read past end of data");
-
 ////
 //// BufReader
 ////
index 0a1c96205c414e8e352fa94f53385318f166d87b..f2b0dab2f3faec39bc97939edfc5a9224176ce6f 100644 (file)
@@ -428,8 +428,6 @@ bool deSerializeStringToStruct(std::string valstr,
 //// BufReader
 ////
 
-extern SerializationError eof_ser_err;
-
 #define MAKE_BUFREADER_GETNOEX_FXN(T, N, S) \
        inline bool get ## N ## NoEx(T *val)    \
        {                                       \
@@ -445,7 +443,7 @@ extern SerializationError eof_ser_err;
        {                                \
                T val;                       \
                if (!get ## N ## NoEx(&val)) \
-                       throw eof_ser_err;       \
+                       throw SerializationError("Attempted read past end of data"); \
                return val;                  \
        }
 
@@ -502,7 +500,7 @@ public:
        inline void getRawData(void *val, size_t len)
        {
                if (!getRawDataNoEx(val, len))
-                       throw eof_ser_err;
+                       throw SerializationError("Attempted read past end of data");
        }
 
        inline size_t remaining()