mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 19:16:14 +02:00
Fix cppcheck issues
This commit is contained in:
parent
d894cd1853
commit
6e786255e1
11 changed files with 33 additions and 19 deletions
|
@ -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;
|
||||
|
|
|
@ -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<int32_t>(frames) + framesCorrection <= 0))
|
||||
{
|
||||
// Avoid underflow in new char[] constructor.
|
||||
framesCorrection = -static_cast<int32_t>(frames) + 1;
|
||||
|
|
|
@ -559,7 +559,7 @@ public:
|
|||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
|
@ -606,10 +606,15 @@ protected:
|
|||
|
||||
virtual ~Log()
|
||||
{
|
||||
sync();
|
||||
do_sync();
|
||||
}
|
||||
|
||||
int sync() override
|
||||
{
|
||||
return do_sync();
|
||||
}
|
||||
|
||||
int do_sync()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!get_stream().str().empty())
|
||||
|
|
|
@ -64,7 +64,7 @@ void Daemon::daemonize()
|
|||
|
||||
auto user_uid = static_cast<uid_t>(-1);
|
||||
auto user_gid = static_cast<gid_t>(-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);
|
||||
}
|
||||
|
|
|
@ -154,11 +154,11 @@ using message_ptr = std::shared_ptr<msg::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
|
||||
{
|
||||
auto size = static_cast<uint32_t>(val.size());
|
||||
writeVal(stream, val.c_str(), size);
|
||||
auto len = static_cast<uint32_t>(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<char*>(&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<char*>(&val), sizeof(int16_t));
|
||||
// cppcheck-suppress selfAssignment
|
||||
val = SWAP_16(val);
|
||||
}
|
||||
|
||||
void readVal(std::istream& stream, uint32_t& val) const
|
||||
{
|
||||
stream.read(reinterpret_cast<char*>(&val), sizeof(uint32_t));
|
||||
// cppcheck-suppress selfAssignment
|
||||
val = SWAP_32(val);
|
||||
}
|
||||
|
||||
void readVal(std::istream& stream, int32_t& val) const
|
||||
{
|
||||
stream.read(reinterpret_cast<char*>(&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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -45,7 +45,7 @@ private:
|
|||
SampleFormat in_format_;
|
||||
SampleFormat out_format_;
|
||||
#ifdef HAS_SOXR
|
||||
soxr_t soxr_;
|
||||
soxr_t soxr_{nullptr};
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions
|
|||
{
|
||||
headerChunk_.reset(new msg::CodecHeader("flac"));
|
||||
pcmBuffer_ = static_cast<FLAC__int32*>(malloc(pcmBufferSize_ * sizeof(FLAC__int32)));
|
||||
metadata_[0] = nullptr;
|
||||
metadata_[1] = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<msg::CodecHeader>("opus");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue