Fix cppcheck warnings, part 1
This commit is contained in:
parent
f5e42e764f
commit
107e90a2c7
5 changed files with 27 additions and 27 deletions
|
@ -266,9 +266,9 @@ class mouse_generic : public rd_mouse{
|
|||
static std::set< uint16_t > _c_all_vids;
|
||||
static std::set< uint16_t > _c_all_pids;
|
||||
/// USB vendor id, needs to be explicitly set
|
||||
uint16_t _c_mouse_vid;
|
||||
uint16_t _c_mouse_vid = 0;
|
||||
/// USB product id, needs to be explicitly set
|
||||
uint16_t _c_mouse_pid;
|
||||
uint16_t _c_mouse_pid = 0;
|
||||
|
||||
//setting vars
|
||||
rd_profile _s_profile;
|
||||
|
|
|
@ -262,7 +262,7 @@ class mouse_m913 : public rd_mouse{
|
|||
/// USB vendor id
|
||||
static const uint16_t _c_mouse_vid;
|
||||
/// USB product id, needs to be explicitly set
|
||||
uint16_t _c_mouse_pid;
|
||||
uint16_t _c_mouse_pid = 0;
|
||||
|
||||
/// DPI → bytecode
|
||||
static std::map< int, std::array<uint8_t,3> > _c_dpi_codes;
|
||||
|
|
|
@ -68,7 +68,7 @@ rd_mouse::mouse_variant rd_mouse::detect(){
|
|||
return mouse;
|
||||
}
|
||||
|
||||
rd_mouse::mouse_variant rd_mouse::detect( std::string mouse_name ){
|
||||
rd_mouse::mouse_variant rd_mouse::detect( const std::string& mouse_name ){
|
||||
|
||||
rd_mouse::mouse_variant mouse = rd_mouse::monostate();
|
||||
|
||||
|
@ -313,7 +313,7 @@ int rd_mouse::_i_close_mouse(){
|
|||
}
|
||||
|
||||
//decode macro bytecode
|
||||
int rd_mouse::_i_decode_macro( std::vector< uint8_t >& macro_bytes, std::ostream& output, std::string prefix, size_t offset ){
|
||||
int rd_mouse::_i_decode_macro( const std::vector< uint8_t >& macro_bytes, std::ostream& output, const std::string& prefix, size_t offset ){
|
||||
|
||||
// valid offset ?
|
||||
if( offset >= macro_bytes.size() )
|
||||
|
@ -323,7 +323,7 @@ int rd_mouse::_i_decode_macro( std::vector< uint8_t >& macro_bytes, std::ostream
|
|||
|
||||
bool unknown_code = false;
|
||||
|
||||
// failsafe
|
||||
// failsafe, i sometimes gets incremented by >1 which could lead to it being out of bounds
|
||||
if( i >= macro_bytes.size() )
|
||||
break;
|
||||
|
||||
|
@ -456,7 +456,7 @@ int rd_mouse::_i_decode_macro( std::vector< uint8_t >& macro_bytes, std::ostream
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_encode_macro( std::array< uint8_t, 256 >& macro_bytes, std::istream& input, size_t offset ){
|
||||
int rd_mouse::_i_encode_macro( std::array< uint8_t, 256 >& macro_bytes, std::istream& input, const size_t offset ){
|
||||
|
||||
macro_bytes.fill( 0x00 );
|
||||
|
||||
|
@ -606,7 +606,7 @@ int rd_mouse::_i_encode_macro( std::array< uint8_t, 256 >& macro_bytes, std::ist
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_decode_button_mapping( std::array<uint8_t, 4>& bytes, std::string& mapping ){
|
||||
int rd_mouse::_i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, std::string& mapping ){
|
||||
|
||||
std::stringstream output;
|
||||
bool found_name = false;
|
||||
|
@ -776,7 +776,7 @@ int rd_mouse::_i_decode_button_mapping( std::array<uint8_t, 4>& bytes, std::stri
|
|||
return return_value;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array<uint8_t, 4>& bytes ){
|
||||
int rd_mouse::_i_encode_button_mapping( const std::string& mapping, std::array<uint8_t, 4>& bytes ){
|
||||
|
||||
// raw byte values
|
||||
if( std::regex_match( mapping, std::regex("0x[0-9a-fA-F]{8}") ) ){
|
||||
|
@ -933,7 +933,7 @@ int rd_mouse::_i_encode_button_mapping( std::string& mapping, std::array<uint8_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_decode_dpi( std::array<uint8_t, 2>& dpi_bytes, std::string& dpi_string ){
|
||||
int rd_mouse::_i_decode_dpi( const std::array<uint8_t, 2>& dpi_bytes, std::string& dpi_string ){
|
||||
|
||||
std::stringstream conversion_stream;
|
||||
|
||||
|
@ -946,7 +946,7 @@ int rd_mouse::_i_decode_dpi( std::array<uint8_t, 2>& dpi_bytes, std::string& dpi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_decode_lightmode( std::array<uint8_t, 2>& lightmode_bytes, std::string& lightmode_string ){
|
||||
int rd_mouse::_i_decode_lightmode( const std::array<uint8_t, 2>& lightmode_bytes, std::string& lightmode_string ){
|
||||
|
||||
int return_value = 0;
|
||||
|
||||
|
@ -975,7 +975,7 @@ int rd_mouse::_i_decode_lightmode( std::array<uint8_t, 2>& lightmode_bytes, std:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_encode_lightmode( rd_mouse::rd_lightmode lightmode, std::array<uint8_t, 2>& lightmode_bytes ){
|
||||
int rd_mouse::_i_encode_lightmode( const rd_mouse::rd_lightmode lightmode, std::array<uint8_t, 2>& lightmode_bytes ){
|
||||
|
||||
int return_value = 1;
|
||||
|
||||
|
@ -990,7 +990,7 @@ int rd_mouse::_i_encode_lightmode( rd_mouse::rd_lightmode lightmode, std::array<
|
|||
return return_value;
|
||||
}
|
||||
|
||||
int rd_mouse::_i_decode_report_rate( uint8_t report_rate_byte, std::string& report_rate_string ){
|
||||
int rd_mouse::_i_decode_report_rate( const uint8_t report_rate_byte, std::string& report_rate_string ){
|
||||
|
||||
int return_value = 0;
|
||||
|
||||
|
@ -1017,7 +1017,7 @@ int rd_mouse::_i_decode_report_rate( uint8_t report_rate_byte, std::string& repo
|
|||
return return_value;
|
||||
}
|
||||
|
||||
uint8_t rd_mouse::_i_encode_report_rate( rd_mouse::rd_report_rate report_rate ){
|
||||
uint8_t rd_mouse::_i_encode_report_rate( const rd_mouse::rd_report_rate report_rate ){
|
||||
|
||||
uint8_t return_value = 0x08; // = 125 Hz, this should be a safe default in case of an error
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class rd_mouse{
|
|||
* In the case of multiple connected mice, only the first will be detected
|
||||
* \return A mouse_variant containing an object corresponding to the detected mouse, or rd_mouse::monostate
|
||||
*/
|
||||
static mouse_variant detect( std::string mouse_name );
|
||||
static mouse_variant detect( const std::string& mouse_name );
|
||||
|
||||
/// Set whether to try to detach the kernel driver when opening the mouse
|
||||
void set_detach_kernel_driver( bool detach_kernel_driver ){
|
||||
|
@ -188,7 +188,7 @@ class rd_mouse{
|
|||
|
||||
//usb device handling
|
||||
/// libusb device handle
|
||||
libusb_device_handle* _i_handle;
|
||||
libusb_device_handle* _i_handle = nullptr;
|
||||
/// whether to detach kernel driver
|
||||
bool _i_detach_kernel_driver = true;
|
||||
/// set by open_mouse for close_mouse
|
||||
|
@ -222,14 +222,14 @@ class rd_mouse{
|
|||
* \arg offset start decoding from macro_bytes[offset], set to 0 if offset >= macro_bytes.size()
|
||||
* \return 0 if no invalid codes were encountered
|
||||
*/
|
||||
static int _i_decode_macro( std::vector< uint8_t >& macro_bytes, std::ostream& output, std::string prefix, size_t offset );
|
||||
static int _i_decode_macro( const std::vector< uint8_t >& macro_bytes, std::ostream& output, const std::string& prefix, size_t offset );
|
||||
|
||||
/** \brief Encode macro commands to macro bytecode
|
||||
* \arg macro_bytes holds the result
|
||||
* \arg input where the macro commands are read from
|
||||
* \arg offset skips offset bytes at the beginning
|
||||
*/
|
||||
static int _i_encode_macro( std::array< uint8_t, 256 >& macro_bytes, std::istream& input, size_t offset );
|
||||
static int _i_encode_macro( std::array< uint8_t, 256 >& macro_bytes, std::istream& input, const size_t offset );
|
||||
|
||||
/** \brief Decodes the bytes describing a button mapping
|
||||
* \arg bytes the 4 bytes descriping the mapping
|
||||
|
@ -237,7 +237,7 @@ class rd_mouse{
|
|||
* \return 0 if valid button mapping
|
||||
* \see _i_encode_button_mapping
|
||||
*/
|
||||
static int _i_decode_button_mapping( std::array<uint8_t, 4>& bytes, std::string& mapping );
|
||||
static int _i_decode_button_mapping( const std::array<uint8_t, 4>& bytes, std::string& mapping );
|
||||
|
||||
/** \brief Turns a string describing a button mapping into bytecode
|
||||
* \arg mapping button mapping
|
||||
|
@ -245,34 +245,34 @@ class rd_mouse{
|
|||
* \return 0 if valid button mapping
|
||||
* \see _i_decode_button_mapping
|
||||
*/
|
||||
static int _i_encode_button_mapping( std::string& mapping, std::array<uint8_t, 4>& bytes );
|
||||
static int _i_encode_button_mapping( const std::string& mapping, std::array<uint8_t, 4>& bytes );
|
||||
|
||||
/** Convert raw dpi bytes to a string representation (doesn't validate dpi value)
|
||||
* This implementation always outputs the raw bytes as a hexdump,
|
||||
* to support actual DPI values this function needs to be overloaded in the model specific classes.
|
||||
* \return 0 if no error occured
|
||||
*/
|
||||
static int _i_decode_dpi( std::array<uint8_t, 2>& dpi_bytes, std::string& dpi_string );
|
||||
static int _i_decode_dpi( const std::array<uint8_t, 2>& dpi_bytes, std::string& dpi_string );
|
||||
|
||||
/** Convert the bytecode for a lightmode to a string
|
||||
* \return 0 if the lightmode is valid
|
||||
*/
|
||||
static int _i_decode_lightmode( std::array<uint8_t, 2>& lightmode_bytes, std::string& lightmode_string );
|
||||
static int _i_decode_lightmode( const std::array<uint8_t, 2>& lightmode_bytes, std::string& lightmode_string );
|
||||
|
||||
/** Convert a lightmode to bytecode
|
||||
* \return 0 if the lightmode is valid
|
||||
*/
|
||||
static int _i_encode_lightmode( rd_mouse::rd_lightmode lightmode, std::array<uint8_t, 2>& lightmode_bytes );
|
||||
static int _i_encode_lightmode( const rd_mouse::rd_lightmode lightmode, std::array<uint8_t, 2>& lightmode_bytes );
|
||||
|
||||
/** Convert the bytecode for a USB report/poll rate to a string
|
||||
* \return 0 if the report rate is valid
|
||||
*/
|
||||
static int _i_decode_report_rate( uint8_t report_rate_byte, std::string& report_rate_string );
|
||||
static int _i_decode_report_rate( const uint8_t report_rate_byte, std::string& report_rate_string );
|
||||
|
||||
/** Convert a report rate to bytecode
|
||||
* \return the byte representing the given report rate
|
||||
*/
|
||||
static uint8_t _i_encode_report_rate( rd_mouse::rd_report_rate report_rate );
|
||||
static uint8_t _i_encode_report_rate( const rd_mouse::rd_report_rate report_rate );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -361,12 +361,12 @@ int main( int argc, char **argv ){
|
|||
} catch( std::string const &message ){ // close mouse, rethrow
|
||||
|
||||
m.close_mouse();
|
||||
throw message;
|
||||
throw;
|
||||
|
||||
} catch( std::exception const &e ){ // close mouse, rethrow
|
||||
|
||||
m.close_mouse();
|
||||
throw e;
|
||||
throw;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue