Page 1 of 1

cppcheck Supertux

PostPosted: 01 Nov 2013, 11:27
by KroArtem
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.

Re: cppcheck Supertux

PostPosted: 07 Nov 2013, 01:41
by LMH
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.