ppsspp icon indicating copy to clipboard operation
ppsspp copied to clipboard

Code cleanup suggestions

Open fp64 opened this issue 3 years ago • 1 comments

Platform

Linux / BSD

Compiler and build tool versions

GCC 10.2.1

Operating system version

GNU/Linux

Build commands used

./b.sh

What happens

Minor stuff, feel free to disregard.

Tried enabling -Wall, and thought I might as well post the results.

List of warnings in PPSSPP with -Wall.
Suitabe for e.g.
    vim -q warnings.txt
from top-level source directory.
 
Warnings breakdown:
    187 -Wunused-variable
    126 -Wreorder
     92 -Wsign-compare
     21 -Wunknown-pragmas
     20 -Wstringop-truncation
     16 -Wunused-but-set-variable
     16 -Wmaybe-uninitialized
      9 -Wmisleading-indentation
      7 -Wunused-function
      6 -Wclass-memaccess
      3 -Warray-bounds
      2 -Wunused-const-variable=
      2 -Wsizeof-pointer-div
      2 -Wrestrict
      1 -Wswitch
      1 -Wstringop-overflow=
      1 -Wsizeof-pointer-memaccess
      1 -Wparentheses
      1 -Wcpp

Full results: warnings.txt (also at pastebin).

  • Didn't look at some of the largest groups: -Wunused-variable, -Wreorder, -Wsign-compare, -Wunused-but-set-variable.
  • -Warray-bounds in GPU/Software/Clipper.cpp seems safe (I think inlist[n] = inlist[0]; means at most 4 vertices are generated, not 5, but poor GCC is confused).
  • -Wunknown-pragmas is unguarded MSVC pragmas.
  • -Wsizeof-pointer-div is, according to comment, intentional for compatbility. Warning is explicitly disabled but for clang only, not GCC.
  • -Wstringop-truncation seems intentional use of strncpy.
  • -Wrestrict and -Wstringop-overflow= may or may not be false positives (there are GCC bugs filed against these warnings).

Unrelated, but printf("Leaving main"); in SDL/SDLMain.cpp lacks a newline which looks a bit off when running from commandline. In the same file, System_GetPropertyInt does not implement screen size queries (giving Longest display side: -1 pixels. Choosing scale 1 in log), however SDL_GetCurrentDisplayMode is used elsewhere.

PPSSPP version affected

v1.12.3-1777-ga35d26190

Last working version

No response

Checklist

  • [X] Test in the latest git build in case it's already fixed.
  • [X] Make sure to run git submodule update --init --recursive before building.
  • [X] Search for other reports of the same issue.
  • [X] Try deleting the build directory and running the build again.
  • [ ] Check GitHub Actions, which builds every merge and PR.
  • [ ] Include logs and help us reproduce.

fp64 avatar Aug 14 '22 16:08 fp64

unused-variable is probably mostly from constants defined in header files that are not universally referenced in all cpp files. unused-function is probably mostly debug functions and other-platform functions. Yes, we could add a mess of more ifdefs and duplicate more code to remove them, but the duplicate functions don't really hurt anyone or the final executable.

From time to time, I clean up warnings and go through them, though I focus on the enabled warnings which are less noisy than i.e. the above.

I've seen issues like this opened before, i.e. #8386 and #8408, and usually the paste of warnings becomes outdated as other things have changed. Pull requests or specific concerns (such as the printf thing, etc.) are a better fit for issues in my opinion.

-[Unknown]

unknownbrackets avatar Aug 14 '22 18:08 unknownbrackets

I can do a PR for SDLMain changes, and a couple of really low-hanging-fruit warnings, while at it.

fp64 avatar Aug 16 '22 17:08 fp64

...and done.

fp64 avatar Aug 16 '22 17:08 fp64

With this the issue can be closed, probably.

fp64 avatar Aug 17 '22 11:08 fp64