improvements reported by cppcheck

This commit is contained in:
Isaac Connor 2020-11-01 16:11:19 -05:00
parent 787953559d
commit 1257a7ea37
16 changed files with 82 additions and 76 deletions

View File

@ -49,7 +49,7 @@ protected:
const int &mWd;
protected:
CommsBase( int &rd, int &wd ) : mRd( rd ), mWd( wd ) {
CommsBase(const int &rd, const int &wd) : mRd(rd), mWd(wd) {
}
virtual ~CommsBase() {
}
@ -62,10 +62,10 @@ public:
public:
int getReadDesc() const {
return( mRd );
return mRd;
}
int getWriteDesc() const {
return( mWd );
return mWd;
}
int getMaxDesc() const {
return( mRd>mWd?mRd:mWd );

View File

@ -112,8 +112,9 @@ public:
double DecimalValue() const;
const char *StringValue() const;
ConfigItem &operator=(const ConfigItem item) {
Copy(item);return *this;
ConfigItem &operator=(const ConfigItem &item) {
Copy(item);
return *this;
}
inline operator bool() const {
return BooleanValue();

View File

@ -48,12 +48,12 @@ public:
return( result );
}
inline bool operator==( const Coord &coord ) { return( x == coord.x && y == coord.y ); }
inline bool operator!=( const Coord &coord ) { return( x != coord.x || y != coord.y ); }
inline bool operator>( const Coord &coord ) { return( x > coord.x && y > coord.y ); }
inline bool operator>=( const Coord &coord ) { return( !(operator<(coord)) ); }
inline bool operator<( const Coord &coord ) { return( x < coord.x && y < coord.y ); }
inline bool operator<=( const Coord &coord ) { return( !(operator>(coord)) ); }
inline bool operator==( const Coord &coord ) const { return( x == coord.x && y == coord.y ); }
inline bool operator!=( const Coord &coord ) const { return( x != coord.x || y != coord.y ); }
inline bool operator>( const Coord &coord ) const { return( x > coord.x && y > coord.y ); }
inline bool operator>=( const Coord &coord ) const { return( !(operator<(coord)) ); }
inline bool operator<( const Coord &coord ) const { return( x < coord.x && y < coord.y ); }
inline bool operator<=( const Coord &coord ) const { return( !(operator>(coord)) ); }
inline Coord &operator+=( const Coord &coord ) { x += coord.x; y += coord.y; return( *this ); }
inline Coord &operator-=( const Coord &coord ) { x -= coord.x; y -= coord.y; return( *this ); }

View File

@ -28,7 +28,7 @@ class zmDbRow {
MYSQL_RES *result_set;
MYSQL_ROW row;
public:
zmDbRow() { result_set = nullptr; row = nullptr; };
zmDbRow() : result_set(nullptr), row(nullptr) { };
MYSQL_RES *fetch( const char *query );
zmDbRow( MYSQL_RES *, MYSQL_ROW *row );
~zmDbRow();

View File

@ -571,6 +571,7 @@ void Event::AddFramesInternal(int n_frames, int start_frame, Image **images, str
void Event::WriteDbFrames() {
char *frame_insert_values_ptr = (char *)&frame_insert_sql + 90; // 90 == strlen(frame_insert_sql);
Debug(1, "Inserting %d frames", frame_data.size());
while ( frame_data.size() ) {
Frame *frame = frame_data.front();
frame_data.pop();
@ -586,8 +587,9 @@ void Event::WriteDbFrames() {
frame->score);
delete frame;
}
*(frame_insert_values_ptr-1) = '\0'; // The -2 is for the extra , added for values above
*(frame_insert_values_ptr-1) = '\0'; // The -1 is for the extra , added for values above
db_mutex.lock();
Debug(1, "SQL: %s", frame_insert_sql);
int rc = mysql_query(&dbconn, frame_insert_sql);
db_mutex.unlock();

View File

@ -113,14 +113,14 @@ class Event {
~Event();
uint64_t Id() const { return id; }
const std::string &Cause() { return cause; }
const std::string &Cause() const { return cause; }
int Frames() const { return frames; }
int AlarmFrames() const { return alarm_frames; }
const struct timeval &StartTime() const { return start_time; }
const struct timeval &EndTime() const { return end_time; }
struct timeval &StartTime() { return start_time; }
struct timeval &EndTime() { return end_time; }
struct timeval &StartTime() const { return start_time; }
struct timeval &EndTime() const { return end_time; }
bool SendFrameImage( const Image *image, bool alarm_frame=false );
bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false );
@ -146,7 +146,7 @@ class Event {
return Event::getSubPath( localtime( time ) );
}
const char* getEventFile(void) {
const char* getEventFile(void) const {
return video_file.c_str();
}

View File

@ -22,8 +22,7 @@
#include <string>
class Exception
{
class Exception {
protected:
typedef enum { INFO, WARNING, ERROR, FATAL } Severity;
@ -32,33 +31,28 @@ protected:
Severity mSeverity;
public:
Exception( const std::string &message, Severity severity=ERROR ) : mMessage( message ), mSeverity( severity )
explicit Exception(const std::string &message, const Severity severity=ERROR) :
mMessage(message),
mSeverity(severity)
{
}
public:
const std::string &getMessage() const
{
return( mMessage );
const std::string &getMessage() const {
return mMessage;
}
Severity getSeverity() const
{
return( mSeverity );
Severity getSeverity() const {
return mSeverity;
}
bool isInfo() const
{
return( mSeverity == INFO );
bool isInfo() const {
return mSeverity == INFO;
}
bool isWarning() const
{
bool isWarning() const {
return( mSeverity == WARNING );
}
bool isError() const
{
bool isError() const {
return( mSeverity == ERROR );
}
bool isFatal() const
{
bool isFatal() const {
return( mSeverity == FATAL );
}
};

View File

@ -68,19 +68,26 @@ class FifoStream : public StreamBase {
);
protected:
typedef enum { MJPEG, RAW } StreamType;
typedef enum { UNKNOWN, MJPEG, RAW } StreamType;
StreamType stream_type;
bool sendMJEGFrames();
bool sendRAWFrames();
void processCommand(const CmdMsg *msg) {}
public:
FifoStream() {}
FifoStream() :
stream_path(nullptr),
fd(0),
total_read(0),
bytes_read(0),
frame_count(0),
stream_type(UNKNOWN)
{}
static void fifo_create_if_missing(
const char * path,
bool delete_fake_fifo = true);
void setStreamStart(const char * path);
void setStreamStart(int monitor_id, const char * format);
void runStream();
void runStream() override;
};
#endif // ZM_FIFO_H

View File

@ -153,17 +153,17 @@ public:
int Palette() const { return( palette ); }
int Extras() const { return( extras ); }
int Brightness( int p_brightness=-1 );
int Hue( int p_hue=-1 );
int Colour( int p_colour=-1 );
int Contrast( int p_contrast=-1 );
int Brightness( int p_brightness=-1 ) override;
int Hue( int p_hue=-1 ) override;
int Colour( int p_colour=-1 ) override;
int Contrast( int p_contrast=-1 ) override;
int PrimeCapture();
int PreCapture();
int Capture( Image &image );
int PostCapture();
int CaptureAndRecord( Image &image, timeval recording, char* event_directory ) {return(0);};
int Close() { return 0; };
int PrimeCapture()override ;
int PreCapture()override ;
int Capture( Image &image )override ;
int PostCapture()override ;
int CaptureAndRecord( Image &image, timeval recording, char* event_directory ) override {return(0);};
int Close() override { return 0; };
static bool GetCurrentSettings( const char *device, char *output, int version, bool verbose );
};

View File

@ -121,7 +121,7 @@ private:
Logger();
~Logger();
int limit(int level) {
int limit(const int level) const {
if ( level > DEBUG9 )
return DEBUG9;
if ( level < NOLOG )
@ -163,7 +163,7 @@ public:
}
Level level(Level=NOOPT);
bool debugOn() {
bool debugOn() const {
return mEffectiveLevel >= DEBUG1;
}

View File

@ -26,7 +26,7 @@
inline void* zm_mallocaligned(unsigned int reqalignment, size_t reqsize) {
uint8_t* retptr;
#if HAVE_POSIX_MEMALIGN
if ( posix_memalign((void**)&retptr,reqalignment,reqsize) != 0 )
if ( posix_memalign((void**)&retptr, reqalignment, reqsize) != 0 )
return nullptr;
return retptr;
@ -39,7 +39,7 @@ inline void* zm_mallocaligned(unsigned int reqalignment, size_t reqsize) {
alloc = retptr + sizeof(void*);
if(((long)alloc % reqalignment) != 0)
if ( ((long)alloc % reqalignment) != 0 )
alloc = alloc + (reqalignment - ((long)alloc % reqalignment));
/* Store a pointer before to the start of the block, just before returned aligned memory */

View File

@ -444,7 +444,7 @@ public:
inline Function GetFunction() const {
return( function );
}
inline bool Enabled() {
inline bool Enabled() const {
if ( function <= MONITOR )
return false;
return enabled;
@ -452,17 +452,17 @@ public:
inline const char *EventPrefix() const {
return event_prefix;
}
inline bool Ready() {
inline bool Ready() const {
if ( function <= MONITOR )
return false;
return( image_count > ready_count );
}
inline bool Active() {
inline bool Active() const {
if ( function <= MONITOR )
return false;
return( enabled && shared_data->active );
}
inline bool Exif() {
inline bool Exif() const {
return embed_exif;
}
Orientation getOrientation() const;
@ -479,7 +479,7 @@ public:
uint64_t GetVideoWriterEventId() const { return video_store_data->current_event; }
void SetVideoWriterEventId( unsigned long long p_event_id ) { video_store_data->current_event = p_event_id; }
struct timeval GetVideoWriterStartTime() const { return video_store_data->recording; }
void SetVideoWriterStartTime(struct timeval &t) { video_store_data->recording = t; }
void SetVideoWriterStartTime(const struct timeval &t) { video_store_data->recording = t; }
unsigned int GetPreEventCount() const { return pre_event_count; };
struct timeval GetVideoBufferDuration() const { return video_buffer_duration; };
@ -505,7 +505,7 @@ public:
inline time_t getStartupTime() const { return shared_data->startup_time; }
inline void setStartupTime( time_t p_time ) { shared_data->startup_time = p_time; }
int LabelSize() { return label_size; }
int LabelSize() const { return label_size; }
void actionReload();
void actionEnable();

View File

@ -31,7 +31,7 @@ extern "C" {
}
class zm_packetqueue {
public:
zm_packetqueue(int max_stream_id);
explicit zm_packetqueue(int max_stream_id);
virtual ~zm_packetqueue();
bool queuePacket(AVPacket* packet, struct timeval *timestamp);
bool queuePacket(ZMPacket* packet);

View File

@ -76,7 +76,9 @@ struct DeltaTimeval
#define USEC_PER_SEC 1000000
#define MSEC_PER_SEC 1000
/*
extern struct timeval tv;
*/
inline int tvDiffUsec( struct timeval first, struct timeval last )
{

View File

@ -46,7 +46,7 @@ class User {
User();
explicit User(const MYSQL_ROW &dbrow);
~User();
User(User &u) { Copy(u); }
User(const User &u) { Copy(u); }
void Copy(const User &u);
User& operator=(const User &u) {
Copy(u); return *this;

View File

@ -482,7 +482,7 @@ int main(int argc, char *argv[]) {
} // end if ! MONITOR
if ( verbose ) {
printf("Monitor %d(%s)\n", monitor->Id(), monitor->Name());
printf("Monitor %u(%s)\n", monitor->Id(), monitor->Name());
}
if ( !monitor->connect() ) {
Error("Can't connect to capture daemon: %d %s", monitor->Id(), monitor->Name());
@ -521,19 +521,19 @@ int main(int argc, char *argv[]) {
}
if ( function & ZMU_READ_IDX ) {
if ( verbose )
printf("Last read index: %d\n", monitor->GetLastReadIndex());
printf("Last read index: %u\n", monitor->GetLastReadIndex());
else {
if ( have_output ) fputc(separator, stdout);
printf("%d", monitor->GetLastReadIndex());
printf("%u", monitor->GetLastReadIndex());
have_output = true;
}
}
if ( function & ZMU_WRITE_IDX ) {
if ( verbose ) {
printf("Last write index: %d\n", monitor->GetLastWriteIndex());
printf("Last write index: %u\n", monitor->GetLastWriteIndex());
} else {
if ( have_output ) fputc(separator, stdout);
printf("%d", monitor->GetLastWriteIndex());
printf("%u", monitor->GetLastWriteIndex());
have_output = true;
}
}
@ -558,9 +558,9 @@ int main(int argc, char *argv[]) {
if ( function & ZMU_IMAGE ) {
if ( verbose ) {
if ( image_idx == -1 )
printf("Dumping last image captured to Monitor%d.jpg", monitor->Id());
printf("Dumping last image captured to Monitor%u.jpg", monitor->Id());
else
printf("Dumping buffer image %d to Monitor%d.jpg", image_idx, monitor->Id());
printf("Dumping buffer image %d to Monitor%u.jpg", image_idx, monitor->Id());
if ( scale != -1 )
printf(", scaling by %d%%", scale);
printf("\n");
@ -569,7 +569,7 @@ int main(int argc, char *argv[]) {
}
if ( function & ZMU_ZONES ) {
if ( verbose )
printf("Dumping zone image to Zones%d.jpg\n", monitor->Id());
printf("Dumping zone image to Zones%u.jpg\n", monitor->Id());
monitor->DumpZoneImage(zoneString);
}
if ( function & ZMU_ALARM ) {
@ -735,17 +735,17 @@ int main(int argc, char *argv[]) {
Debug(1, "Got %d monitors", mysql_num_rows(result));
printf("%4s%5s%6s%9s%14s%6s%6s%8s%8s\n", "Id", "Func", "State", "TrgState", "LastImgTim", "RdIdx", "WrIdx", "LastEvt", "FrmRate");
for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
int mon_id = atoi(dbrow[0]);
int function = atoi(dbrow[1]);
if ( !user || user->canAccess(mon_id) ) {
if ( function > 1 ) {
Monitor *monitor = Monitor::Load(mon_id, false, Monitor::QUERY);
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
int monitor_id = atoi(dbrow[0]);
int monitor_function = atoi(dbrow[1]);
if ( !user || user->canAccess(monitor_id) ) {
if ( monitor_function > 1 ) {
Monitor *monitor = Monitor::Load(monitor_id, false, Monitor::QUERY);
if ( monitor && monitor->connect() ) {
struct timeval tv = monitor->GetTimestamp();
printf( "%4d%5d%6d%9d%11ld.%02ld%6d%6d%8" PRIu64 "%8.2f\n",
monitor->Id(),
function,
monitor_function,
monitor->GetState(),
monitor->GetTriggerState(),
tv.tv_sec, tv.tv_usec/10000,