Fix cppcheck issues

This commit is contained in:
badaix 2023-12-30 11:37:35 +01:00
parent d894cd1853
commit 6e786255e1
11 changed files with 33 additions and 19 deletions

View file

@ -12,6 +12,10 @@ enum IPVersion
struct mDNSResult struct mDNSResult
{ {
mDNSResult() : ip_version(IPv4), iface_idx(0), port(0), valid(false)
{
}
IPVersion ip_version; IPVersion ip_version;
int iface_idx; int iface_idx;
std::string ip; std::string ip;

View file

@ -155,7 +155,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frames, int32_t framesCorrection) cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frames, int32_t framesCorrection)
{ {
if (framesCorrection < 0 && frames + framesCorrection <= 0) if (framesCorrection < 0 && (static_cast<int32_t>(frames) + framesCorrection <= 0))
{ {
// Avoid underflow in new char[] constructor. // Avoid underflow in new char[] constructor.
framesCorrection = -static_cast<int32_t>(frames) + 1; framesCorrection = -static_cast<int32_t>(frames) + 1;

View file

@ -559,7 +559,7 @@ public:
} }
/// Without "init" every LOG(X) will simply go to clog /// Without "init" every LOG(X) will simply go to clog
static void init(const std::vector<log_sink_ptr> log_sinks = {}) static void init(const std::vector<log_sink_ptr>& log_sinks = {})
{ {
Log::instance().log_sinks_.clear(); Log::instance().log_sinks_.clear();
@ -606,10 +606,15 @@ protected:
virtual ~Log() virtual ~Log()
{ {
sync(); do_sync();
} }
int sync() override int sync() override
{
return do_sync();
}
int do_sync()
{ {
std::lock_guard<std::recursive_mutex> lock(mutex_); std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!get_stream().str().empty()) if (!get_stream().str().empty())

View file

@ -64,7 +64,7 @@ void Daemon::daemonize()
auto user_uid = static_cast<uid_t>(-1); auto user_uid = static_cast<uid_t>(-1);
auto user_gid = static_cast<gid_t>(-1); auto user_gid = static_cast<gid_t>(-1);
std::string user_name; // std::string user_name;
// #ifdef FREEBSD // #ifdef FREEBSD
// bool had_group = false; // bool had_group = false;
// #endif // #endif
@ -76,7 +76,7 @@ void Daemon::daemonize()
throw SnapException("no such user \"" + user_ + "\""); throw SnapException("no such user \"" + user_ + "\"");
user_uid = pwd->pw_uid; user_uid = pwd->pw_uid;
user_gid = pwd->pw_gid; user_gid = pwd->pw_gid;
user_name = strdup(user_.c_str()); // user_name = strdup(user_.c_str());
/// this is needed by libs such as arts /// this is needed by libs such as arts
setenv("HOME", pwd->pw_dir, 1); setenv("HOME", pwd->pw_dir, 1);
} }

View file

@ -154,11 +154,11 @@ using message_ptr = std::shared_ptr<msg::BaseMessage>;
struct BaseMessage struct BaseMessage
{ {
BaseMessage() : type(message_type::kBase), id(0), refersTo(0) BaseMessage() : BaseMessage(message_type::kBase)
{ {
} }
BaseMessage(message_type type_) : type(type_), id(0), refersTo(0) BaseMessage(message_type type_) : type(type_), id(0), refersTo(0), size(0)
{ {
} }
@ -272,8 +272,8 @@ protected:
void writeVal(std::ostream& stream, const std::string& val) const void writeVal(std::ostream& stream, const std::string& val) const
{ {
auto size = static_cast<uint32_t>(val.size()); auto len = static_cast<uint32_t>(val.size());
writeVal(stream, val.c_str(), size); writeVal(stream, val.c_str(), len);
} }
@ -293,6 +293,7 @@ protected:
void readVal(std::istream& stream, uint16_t& val) const void readVal(std::istream& stream, uint16_t& val) const
{ {
stream.read(reinterpret_cast<char*>(&val), sizeof(uint16_t)); stream.read(reinterpret_cast<char*>(&val), sizeof(uint16_t));
// cppcheck-suppress selfAssignment
val = SWAP_16(val); val = SWAP_16(val);
} }
@ -305,18 +306,21 @@ protected:
void readVal(std::istream& stream, int16_t& val) const void readVal(std::istream& stream, int16_t& val) const
{ {
stream.read(reinterpret_cast<char*>(&val), sizeof(int16_t)); stream.read(reinterpret_cast<char*>(&val), sizeof(int16_t));
// cppcheck-suppress selfAssignment
val = SWAP_16(val); val = SWAP_16(val);
} }
void readVal(std::istream& stream, uint32_t& val) const void readVal(std::istream& stream, uint32_t& val) const
{ {
stream.read(reinterpret_cast<char*>(&val), sizeof(uint32_t)); stream.read(reinterpret_cast<char*>(&val), sizeof(uint32_t));
// cppcheck-suppress selfAssignment
val = SWAP_32(val); val = SWAP_32(val);
} }
void readVal(std::istream& stream, int32_t& val) const void readVal(std::istream& stream, int32_t& val) const
{ {
stream.read(reinterpret_cast<char*>(&val), sizeof(int32_t)); stream.read(reinterpret_cast<char*>(&val), sizeof(int32_t));
// cppcheck-suppress selfAssignment
val = SWAP_32(val); val = SWAP_32(val);
} }
@ -329,10 +333,10 @@ protected:
void readVal(std::istream& stream, std::string& val) const void readVal(std::istream& stream, std::string& val) const
{ {
uint32_t size; uint32_t len;
readVal(stream, size); readVal(stream, len);
val.resize(size); val.resize(len);
stream.read(&val[0], size); stream.read(&val[0], len);
} }

View file

@ -29,7 +29,6 @@ static constexpr auto LOG_TAG = "Resampler";
Resampler::Resampler(const SampleFormat& in_format, const SampleFormat& out_format) : in_format_(in_format), out_format_(out_format) Resampler::Resampler(const SampleFormat& in_format, const SampleFormat& out_format) : in_format_(in_format), out_format_(out_format)
{ {
#ifdef HAS_SOXR #ifdef HAS_SOXR
soxr_ = nullptr;
if ((out_format_.rate() != in_format_.rate()) || (out_format_.bits() != in_format_.bits())) if ((out_format_.rate() != in_format_.rate()) || (out_format_.bits() != in_format_.bits()))
{ {
LOG(INFO, LOG_TAG) << "Resampling from " << in_format_.toString() << " to " << out_format_.toString() << "\n"; LOG(INFO, LOG_TAG) << "Resampling from " << in_format_.toString() << " to " << out_format_.toString() << "\n";

View file

@ -45,7 +45,7 @@ private:
SampleFormat in_format_; SampleFormat in_format_;
SampleFormat out_format_; SampleFormat out_format_;
#ifdef HAS_SOXR #ifdef HAS_SOXR
soxr_t soxr_; soxr_t soxr_{nullptr};
#endif #endif
}; };

View file

@ -99,7 +99,7 @@ static int mkdirRecursive(const char* path, mode_t mode)
if (p.empty()) if (p.empty())
continue; continue;
ss << "/" << p; ss << "/" << p;
int res = mkdir(ss.str().c_str(), mode); res = mkdir(ss.str().c_str(), mode);
if ((res != 0) && (errno != EEXIST)) if ((res != 0) && (errno != EEXIST))
return res; return res;
} }

View file

@ -34,6 +34,8 @@ FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions
{ {
headerChunk_.reset(new msg::CodecHeader("flac")); headerChunk_.reset(new msg::CodecHeader("flac"));
pcmBuffer_ = static_cast<FLAC__int32*>(malloc(pcmBufferSize_ * sizeof(FLAC__int32))); pcmBuffer_ = static_cast<FLAC__int32*>(malloc(pcmBufferSize_ * sizeof(FLAC__int32)));
metadata_[0] = nullptr;
metadata_[1] = nullptr;
} }

View file

@ -46,7 +46,7 @@ void assign(void* pointer, T val)
} // namespace } // namespace
OpusEncoder::OpusEncoder(const std::string& codecOptions) : Encoder(codecOptions), enc_(nullptr) OpusEncoder::OpusEncoder(const std::string& codecOptions) : Encoder(codecOptions), enc_(nullptr), remainder_max_size_(0)
{ {
headerChunk_ = make_unique<msg::CodecHeader>("opus"); headerChunk_ = make_unique<msg::CodecHeader>("opus");
} }

View file

@ -40,7 +40,6 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
{ {
std::string ret; std::string ret;
int i = 0; int i = 0;
int j = 0;
unsigned char char_array_3[3]; unsigned char char_array_3[3];
unsigned char char_array_4[4]; unsigned char char_array_4[4];
@ -62,6 +61,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
if (i != 0) if (i != 0)
{ {
int j = 0;
for (j = i; j < 3; j++) for (j = i; j < 3; j++)
char_array_3[j] = '\0'; char_array_3[j] = '\0';
@ -85,7 +85,6 @@ std::string base64_decode(std::string const& encoded_string)
{ {
int in_len = encoded_string.size(); int in_len = encoded_string.size();
int i = 0; int i = 0;
int j = 0;
int in_ = 0; int in_ = 0;
unsigned char char_array_4[4], char_array_3[3]; unsigned char char_array_4[4], char_array_3[3];
std::string ret; std::string ret;
@ -111,6 +110,7 @@ std::string base64_decode(std::string const& encoded_string)
if (i != 0) if (i != 0)
{ {
int j = 0;
for (j = i; j < 4; j++) for (j = i; j < 4; j++)
char_array_4[j] = 0; char_array_4[j] = 0;