mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-14 20:20:35 +00:00
Merge branch 'fix-enum' into next
Fix deprecated enum usage (in Clang 10, arithmetic between different enumeration types is deprecated [-Wdeprecated-anon-enum-enum-conversion]) Fix defect detected by Coverity Scan in Rtcm_Message class (Destination buffer too small: Buffer this->data_ contains 0 characters and is not null-terminated. Copying 6 characters from it overruns this->data_)
This commit is contained in:
commit
487971fd83
@ -34,6 +34,7 @@
|
||||
#include <glog/logging.h>
|
||||
#include <pmt/pmt.h>
|
||||
#include <algorithm> // for min
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint>
|
||||
@ -502,14 +503,8 @@ private:
|
||||
class Rtcm_Message
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
header_length = 6
|
||||
};
|
||||
enum
|
||||
{
|
||||
max_body_length = 1029
|
||||
};
|
||||
static const std::size_t header_length = 6;
|
||||
static const std::size_t max_body_length = 1029;
|
||||
|
||||
Rtcm_Message()
|
||||
: body_length_(0)
|
||||
@ -518,12 +513,12 @@ private:
|
||||
|
||||
const char* data() const
|
||||
{
|
||||
return data_;
|
||||
return data_.data();
|
||||
}
|
||||
|
||||
char* data()
|
||||
{
|
||||
return data_;
|
||||
return data_.data();
|
||||
}
|
||||
|
||||
inline std::size_t length() const
|
||||
@ -533,12 +528,12 @@ private:
|
||||
|
||||
const char* body() const
|
||||
{
|
||||
return data_ + header_length;
|
||||
return data_.data() + header_length;
|
||||
}
|
||||
|
||||
char* body()
|
||||
{
|
||||
return data_ + header_length;
|
||||
return data_.data() + header_length;
|
||||
}
|
||||
|
||||
std::size_t body_length() const
|
||||
@ -558,14 +553,14 @@ private:
|
||||
inline bool decode_header()
|
||||
{
|
||||
char header[header_length + 1] = "";
|
||||
std::strncat(header, data_, header_length);
|
||||
std::strncat(header, data_.data(), header_length);
|
||||
if (header[0] != 'G' || header[1] != 'S')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char header2_[header_length - 1] = "";
|
||||
std::strncat(header2_, data_ + 2, header_length - 2);
|
||||
std::strncat(header2_, data_.data() + 2, header_length - 2);
|
||||
body_length_ = std::atoi(header2_);
|
||||
if (body_length_ == 0)
|
||||
{
|
||||
@ -584,11 +579,11 @@ private:
|
||||
{
|
||||
char header[header_length + 1] = "";
|
||||
std::snprintf(header, header_length + 1, "GS%4d", std::max(std::min(static_cast<int>(body_length_), static_cast<int>(max_body_length)), 0));
|
||||
std::memcpy(data_, header, header_length);
|
||||
std::memcpy(data_.data(), header, header_length);
|
||||
}
|
||||
|
||||
private:
|
||||
char data_[header_length + max_body_length];
|
||||
std::array<char, header_length + max_body_length> data_{};
|
||||
std::size_t body_length_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user