diff --git a/plugin/common/plugin.h b/plugin/common/plugin.h index d55ae9e6..f96ed9ff 100644 --- a/plugin/common/plugin.h +++ b/plugin/common/plugin.h @@ -16,6 +16,7 @@ #ifndef TRT_PLUGIN_H #define TRT_PLUGIN_H #include "NvInferPlugin.h" +#include #include #include #include @@ -57,7 +58,7 @@ class BaseCreator : public IPluginCreator template void write(char*& buffer, const T& val) { - *reinterpret_cast(buffer) = val; + std::memcpy(buffer, &val, sizeof(T)); buffer += sizeof(T); } @@ -65,7 +66,8 @@ void write(char*& buffer, const T& val) template T read(const char*& buffer) { - T val = *reinterpret_cast(buffer); + T val; + std::memcpy(&val, buffer, sizeof(T)); buffer += sizeof(T); return val; } diff --git a/samples/opensource/sampleUffPluginV2Ext/sampleUffPluginV2Ext.cpp b/samples/opensource/sampleUffPluginV2Ext/sampleUffPluginV2Ext.cpp index 96301dd6..430819c5 100644 --- a/samples/opensource/sampleUffPluginV2Ext/sampleUffPluginV2Ext.cpp +++ b/samples/opensource/sampleUffPluginV2Ext/sampleUffPluginV2Ext.cpp @@ -18,10 +18,10 @@ #include "NvUffParser.h" #include #include +#include #include #include #include -#include #include #include @@ -579,14 +579,15 @@ class UffPoolPluginV2 : public IPluginV2IOExt template void write(char*& buffer, const T& val) const { - *reinterpret_cast(buffer) = val; + std::memcpy(buffer, &val, sizeof(T)); buffer += sizeof(T); } template T read(const char*& buffer) const { - T val = *reinterpret_cast(buffer); + T val; + std::memcpy(&val, buffer, sizeof(T)); buffer += sizeof(T); return val; }