From 71f13a7c9a4f9fbc5c73df7a2f73d13051d0e9ad Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 12 Nov 2017 10:27:47 -0500 Subject: [PATCH] optimisations/fixes from cppcheck --- src/zm_user.cpp | 2 +- src/zm_utils.cpp | 6 +++--- src/zm_utils.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/zm_user.cpp b/src/zm_user.cpp index 58de254bd..217e1daff 100644 --- a/src/zm_user.cpp +++ b/src/zm_user.cpp @@ -90,12 +90,12 @@ bool User::canAccess( int monitor_id ) { User *zmLoadUser( const char *username, const char *password ) { char sql[ZM_SQL_SML_BUFSIZ] = ""; char safer_username[65]; // current db username size is 32 - char safer_password[129]; // current db password size is 64 // According to docs, size of safer_whatever must be 2*length+1 due to unicode conversions + null terminator. mysql_real_escape_string(&dbconn, safer_username, username, strlen( username ) ); if ( password ) { + char safer_password[129]; // current db password size is 64 mysql_real_escape_string(&dbconn, safer_password, password, strlen( password ) ); snprintf( sql, sizeof(sql), "select Username, Password, Enabled, Stream+0, Events+0, Control+0, Monitors+0, System+0, MonitorIds from Users where Username = '%s' and Password = password('%s') and Enabled = 1", safer_username, safer_password ); } else { diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index f6ce68089..05c58edfe 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -80,7 +80,7 @@ const std::string stringtf( const char *format, ... ) return( tempString ); } -const std::string stringtf( const std::string &format, ... ) +const std::string stringtf( const std::string format, ... ) { va_list ap; char tempBuffer[8192]; @@ -100,7 +100,7 @@ bool startsWith( const std::string &haystack, const std::string &needle ) return( haystack.substr( 0, needle.length() ) == needle ); } -StringVector split( const std::string &string, const std::string chars, int limit ) +StringVector split( const std::string &string, const std::string &chars, int limit ) { StringVector stringVector; std::string tempString = string; @@ -134,7 +134,7 @@ StringVector split( const std::string &string, const std::string chars, int limi return( stringVector ); } -const std::string join(const StringVector v, const char * delim ) { +const std::string join(const StringVector &v, const char * delim ) { std::stringstream ss; for(size_t i = 0; i < v.size(); ++i) { diff --git a/src/zm_utils.h b/src/zm_utils.h index 961389611..a10c89f48 100644 --- a/src/zm_utils.h +++ b/src/zm_utils.h @@ -33,11 +33,11 @@ std::string trimSet(std::string str, std::string trimset); std::string replaceAll(std::string str, std::string from, std::string to); const std::string stringtf( const char *format, ... ); -const std::string stringtf( const std::string &format, ... ); +const std::string stringtf( const std::string format, ... ); bool startsWith( const std::string &haystack, const std::string &needle ); -StringVector split( const std::string &string, const std::string chars, int limit=0 ); -const std::string join( const StringVector, const char * ); +StringVector split( const std::string &string, const std::string &chars, int limit=0 ); +const std::string join( const StringVector &, const char * ); const std::string base64Encode( const std::string &inString );