diff --git a/client/browseZeroConf/browse_mdns.hpp b/client/browseZeroConf/browse_mdns.hpp index 685366e3..66b172b0 100644 --- a/client/browseZeroConf/browse_mdns.hpp +++ b/client/browseZeroConf/browse_mdns.hpp @@ -12,6 +12,10 @@ enum IPVersion struct mDNSResult { + mDNSResult() : ip_version(IPv4), iface_idx(0), port(0), valid(false) + { + } + IPVersion ip_version; int iface_idx; std::string ip; diff --git a/client/stream.cpp b/client/stream.cpp index c1e47d6f..6c0c3108 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -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) { - if (framesCorrection < 0 && frames + framesCorrection <= 0) + if (framesCorrection < 0 && (static_cast(frames) + framesCorrection <= 0)) { // Avoid underflow in new char[] constructor. framesCorrection = -static_cast(frames) + 1; diff --git a/common/aixlog.hpp b/common/aixlog.hpp index df5343ca..d532baaa 100644 --- a/common/aixlog.hpp +++ b/common/aixlog.hpp @@ -559,7 +559,7 @@ public: } /// Without "init" every LOG(X) will simply go to clog - static void init(const std::vector log_sinks = {}) + static void init(const std::vector& log_sinks = {}) { Log::instance().log_sinks_.clear(); @@ -606,10 +606,15 @@ protected: virtual ~Log() { - sync(); + do_sync(); } int sync() override + { + return do_sync(); + } + + int do_sync() { std::lock_guard lock(mutex_); if (!get_stream().str().empty()) diff --git a/common/daemon.cpp b/common/daemon.cpp index 36588f88..89add969 100644 --- a/common/daemon.cpp +++ b/common/daemon.cpp @@ -64,7 +64,7 @@ void Daemon::daemonize() auto user_uid = static_cast(-1); auto user_gid = static_cast(-1); - std::string user_name; + // std::string user_name; // #ifdef FREEBSD // bool had_group = false; // #endif @@ -76,7 +76,7 @@ void Daemon::daemonize() throw SnapException("no such user \"" + user_ + "\""); user_uid = pwd->pw_uid; 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 setenv("HOME", pwd->pw_dir, 1); } diff --git a/common/message/message.hpp b/common/message/message.hpp index 7e536f54..d9ca8cd7 100644 --- a/common/message/message.hpp +++ b/common/message/message.hpp @@ -154,11 +154,11 @@ using message_ptr = std::shared_ptr; 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 { - auto size = static_cast(val.size()); - writeVal(stream, val.c_str(), size); + auto len = static_cast(val.size()); + writeVal(stream, val.c_str(), len); } @@ -293,6 +293,7 @@ protected: void readVal(std::istream& stream, uint16_t& val) const { stream.read(reinterpret_cast(&val), sizeof(uint16_t)); + // cppcheck-suppress selfAssignment val = SWAP_16(val); } @@ -305,18 +306,21 @@ protected: void readVal(std::istream& stream, int16_t& val) const { stream.read(reinterpret_cast(&val), sizeof(int16_t)); + // cppcheck-suppress selfAssignment val = SWAP_16(val); } void readVal(std::istream& stream, uint32_t& val) const { stream.read(reinterpret_cast(&val), sizeof(uint32_t)); + // cppcheck-suppress selfAssignment val = SWAP_32(val); } void readVal(std::istream& stream, int32_t& val) const { stream.read(reinterpret_cast(&val), sizeof(int32_t)); + // cppcheck-suppress selfAssignment val = SWAP_32(val); } @@ -329,10 +333,10 @@ protected: void readVal(std::istream& stream, std::string& val) const { - uint32_t size; - readVal(stream, size); - val.resize(size); - stream.read(&val[0], size); + uint32_t len; + readVal(stream, len); + val.resize(len); + stream.read(&val[0], len); } diff --git a/common/resampler.cpp b/common/resampler.cpp index b15bf374..929fceae 100644 --- a/common/resampler.cpp +++ b/common/resampler.cpp @@ -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) { #ifdef HAS_SOXR - soxr_ = nullptr; 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"; diff --git a/common/resampler.hpp b/common/resampler.hpp index 6cdc2140..b6b9517e 100644 --- a/common/resampler.hpp +++ b/common/resampler.hpp @@ -45,7 +45,7 @@ private: SampleFormat in_format_; SampleFormat out_format_; #ifdef HAS_SOXR - soxr_t soxr_; + soxr_t soxr_{nullptr}; #endif }; diff --git a/common/utils/file_utils.hpp b/common/utils/file_utils.hpp index d458f276..0fdac284 100644 --- a/common/utils/file_utils.hpp +++ b/common/utils/file_utils.hpp @@ -99,7 +99,7 @@ static int mkdirRecursive(const char* path, mode_t mode) if (p.empty()) continue; ss << "/" << p; - int res = mkdir(ss.str().c_str(), mode); + res = mkdir(ss.str().c_str(), mode); if ((res != 0) && (errno != EEXIST)) return res; } diff --git a/server/encoder/flac_encoder.cpp b/server/encoder/flac_encoder.cpp index 6ffa3a1b..ad1d2700 100644 --- a/server/encoder/flac_encoder.cpp +++ b/server/encoder/flac_encoder.cpp @@ -34,6 +34,8 @@ FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions { headerChunk_.reset(new msg::CodecHeader("flac")); pcmBuffer_ = static_cast(malloc(pcmBufferSize_ * sizeof(FLAC__int32))); + metadata_[0] = nullptr; + metadata_[1] = nullptr; } diff --git a/server/encoder/opus_encoder.cpp b/server/encoder/opus_encoder.cpp index 8ac01300..7046f3f6 100644 --- a/server/encoder/opus_encoder.cpp +++ b/server/encoder/opus_encoder.cpp @@ -46,7 +46,7 @@ void assign(void* pointer, T val) } // 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("opus"); } diff --git a/server/streamreader/base64.cpp b/server/streamreader/base64.cpp index 1e8fe716..608bacc8 100644 --- a/server/streamreader/base64.cpp +++ b/server/streamreader/base64.cpp @@ -40,7 +40,6 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_ { std::string ret; int i = 0; - int j = 0; unsigned char char_array_3[3]; 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) { + int j = 0; for (j = i; j < 3; j++) 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 i = 0; - int j = 0; int in_ = 0; unsigned char char_array_4[4], char_array_3[3]; std::string ret; @@ -111,6 +110,7 @@ std::string base64_decode(std::string const& encoded_string) if (i != 0) { + int j = 0; for (j = i; j < 4; j++) char_array_4[j] = 0;