Skip to content

Commit

Permalink
fix(perception): remove UB reinterpret_cast
Browse files Browse the repository at this point in the history
see autowarefoundation#3215

Signed-off-by: Vincent Richard <richard-v@macnica.co.jp>
  • Loading branch information
VRichardJP committed May 9, 2023
1 parent ce1255a commit 4a49472
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions perception/tensorrt_yolo/lib/src/plugins/nms_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

#include <cuda_runtime_api.h>
#include <stdio.h>
#include <string.h>

#include <cassert>
#include <cmath>
#include <cstring>

using nvinfer1::DataType;
using nvinfer1::DimsExprs;
Expand All @@ -62,14 +62,14 @@ const char * NMS_PLUGIN_NAMESPACE{""};
template <typename T>
void write(char *& buffer, const T & val)
{
*reinterpret_cast<T *>(buffer) = val;
std::memcpy(buffer, &val, sizeof(T));
buffer += sizeof(T);
}

template <typename T>
void read(const char *& buffer, T & val)
{
val = *reinterpret_cast<const T *>(buffer);
std::memcpy(&val, buffer, sizeof(T));
buffer += sizeof(T);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@

#include <cuda_runtime_api.h>
#include <stdio.h>
#include <string.h>

#include <cassert>
#include <cmath>
#include <cstring>
#include <vector>

using nvinfer1::DataType;
Expand All @@ -87,14 +87,14 @@ const char * YOLO_LAYER_PLUGIN_NAMESPACE{""};
template <typename T>
void write(char *& buffer, const T & val)
{
*reinterpret_cast<T *>(buffer) = val;
std::memcpy(buffer, &val, sizeof(T));
buffer += sizeof(T);
}

template <typename T>
void read(const char *& buffer, T & val)
{
val = *reinterpret_cast<const T *>(buffer);
std::memcpy(&val, buffer, sizeof(T));
buffer += sizeof(T);
}
} // namespace
Expand Down
4 changes: 2 additions & 2 deletions system/system_monitor/reader/hdd_reader/hdd_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ int get_nvme_smart_data(int fd, HddInfo * info)
// is from 1 to 1,000, three indicates that the number of 512 byte data
// units written is from 2,001 to 3,000)
info->is_valid_total_data_written_ = true;
info->total_data_written_ = *(reinterpret_cast<uint64_t *>(&data[48]));
std::memcpy(&info->total_data_written_, &data[48], sizeof(uint64_t));

// Bytes 143:128 Power On Hours
info->is_valid_power_on_hours_ = true;
info->power_on_hours_ = *(reinterpret_cast<uint64_t *>(&data[128]));
std::memcpy(&info->power_on_hours_, &data[128], sizeof(uint64_t));

// NVMe S.M.A.R.T has no information of recovered error count
info->is_valid_recovered_error_ = false;
Expand Down

0 comments on commit 4a49472

Please sign in to comment.