cppcheck Supertux

cppcheck Supertux

Postby KroArtem » 01 Nov 2013, 11:27

I've run Supertux source code through cppcheck analysis tool. Patch is attached to this post. It just fixes some warnings.

There is one more warning about joysticks.

Look at this code:
{l Code}: {l Select All Code}
if(left == joy_axis_map.end()) {
      // std::cout << "Unmapped joyaxis " << (int)jaxis.axis << " moved" << std::endl;
    } else {
      if (jaxis.value < -dead_zone)
        set_joy_controls(left->second,  true);
      else if (jaxis.value > dead_zone)
        set_joy_controls(left->second, false);  <<- duplicate code for if and else statements!
      else
        set_joy_controls(left->second, false);  <<- duplicate code for if and else statements!
    }

    if(right == joy_axis_map.end()) {
      // std::cout << "Unmapped joyaxis " << (int)jaxis.axis << " moved" << std::endl;
    } else {
      if (jaxis.value < -dead_zone)
        set_joy_controls(right->second, false);
      else if (jaxis.value > dead_zone)
        set_joy_controls(right->second, true);
      else
        set_joy_controls(right->second, false);
    }

I've marked duplicated code. It's easy to understand (compare with another if/else statement. As I'm not sure what does this piece of code has to do, I left it as it is. But it's definitely a copy-paste error.
Attachments
diff.patch
(3.12 KiB) Downloaded 272 times
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: cppcheck Supertux

Postby LMH » 07 Nov 2013, 01:41

Thanks for the check. I've pushed your patch to the repo as well as some cleanup on the joystick code (it could probably be consolidated more, but I'd have to think about it to make sure). So the warnings you've mentioned should now be addressed.
User avatar
LMH
 
Posts: 105
Joined: 04 Jan 2012, 19:39

Who is online

Users browsing this forum: No registered users and 1 guest

cron