Fix issues found by Cppcheck

These include:

  - [X11Exception.h:16]: Class 'X11Exception' has a constructor
    with 1 argument that is not explicit.

  - [wrapper.cpp:62]: Array index 'i' is used before limits check.

  - [wrapper.cpp:183]: Exception should be caught by reference.
This commit is contained in:
selurvedu 2015-07-27 22:02:07 +00:00
parent 7d5c44d4c4
commit 2602e1710f
2 changed files with 5 additions and 6 deletions

View File

@ -13,7 +13,7 @@ class X11Exception : public std::exception
{ {
public: public:
X11Exception() : _reason("unknown") {} X11Exception() : _reason("unknown") {}
X11Exception(const std::string& what) : _reason(what) {} explicit X11Exception(const std::string& what) : _reason(what) {}
virtual ~X11Exception() throw () {}; virtual ~X11Exception() throw () {};
virtual const char* what() const throw () { return _reason.c_str(); } virtual const char* what() const throw () { return _reason.c_str(); }
@ -21,9 +21,8 @@ private:
std::string _reason; std::string _reason;
}; };
#endif // GAMEEXCEPTION_H_FE39A315_6827_447B_AE62_5FA2C3FD391F #endif // X11EXCEPTION_H_FE39A315_6827_447B_AE62_5FA2C3FD391F
// Local Variables: // Local Variables:
// mode: c++ // mode: c++
// End: // End:

View File

@ -59,7 +59,7 @@ bool print_status(XKeyboard& xkb, string format) {
stringstream r; // resulting string stringstream r; // resulting string
for (size_t i = 0; i < format.length(); ++i) { for (size_t i = 0; i < format.length(); ++i) {
if (format[i] == '%' && i < format.length()-1) { if (i < format.length()-2 && format[i] == '%') {
switch (format[i+1]) { switch (format[i+1]) {
case 'c': case 'c':
r << xkb.currentGroupNum(); r << xkb.currentGroupNum();
@ -180,8 +180,8 @@ int main(int argc, char* argv[])
} }
} }
} }
catch (exception e) { catch (const exception *e) {
cerr << e.what() << endl; cerr << e->what() << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;