Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger plugin: potential cppcheck false positive: uninitvar #1014

Closed
eht16 opened this issue Oct 13, 2020 · 7 comments · Fixed by #1017
Closed

Debugger plugin: potential cppcheck false positive: uninitvar #1014

eht16 opened this issue Oct 13, 2020 · 7 comments · Fixed by #1017

Comments

@eht16
Copy link
Member

eht16 commented Oct 13, 2020

cppcheck 2.2 complains about many ifdefs in the Debugger plugin:

make[5]: Leaving directory '/build/geany-plugins-1.36-1+20201013git06a38f4/debugger/src'
tpage.c:154:62: warning: Uninitialized variable: widgets [uninitvar]
   gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(*widgets[i])), *widgets[i]);
                                                             ^
nofile:0:0: warning: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]

make[4]: *** [Makefile:1686: check-cppcheck] Error 2

When we remove GTK2 code, this might resolve it.

What should we do until then?

  • use --force?
  • refactor the code?
  • ignore?

This breaks the nightly builds for Debian Sid: https://www.geany.org/download/nightly-builds/.

@elextr
Copy link
Member

elextr commented Oct 13, 2020

For the ifdef IIUC cppcheck checks all possible paths through nested #ifdefs eg:

#ifdef A
code 1
#else 
code 2
#endif 

would have the whole file checked twice, once with code 1 and once with code 2 included, but when ifdefs are nested the number of combinations can explode and the check time blow out (one project had their CI run for weeks trying to complete it) so the number of combinations is limited by default.

Maybe best to skip cppcheck on debugger until after 1.37 rather than making big changes to it this close to release.

Extra points for running cppcheck --force on debugger manually to see how long it takes :)

@b4n
Copy link
Member

b4n commented Oct 14, 2020

Is the problem really the ifdefs, or the widgets variable? If it's the var, it looks like a false positive to me.

@elextr
Copy link
Member

elextr commented Oct 14, 2020

I was just going on the title of the issue, I'm sure @eht16 couldn't be wrong. :)

And agree the variable is a false positive, the widgets array is an initialised static null terminated in a loop that stops on null.

@elextr
Copy link
Member

elextr commented Oct 14, 2020

Also most of the ifdefs are GTK_CHECK_VERSION(3, 0, 0) and I don't know how smart cppcheck is to know all instances of that macro will have the same value.

@eht16
Copy link
Member Author

eht16 commented Oct 14, 2020

Oops, even in the log I pasted here I completely overlooked the real error message and just concentrated on the (probably) harmless warning. My random excuse generator says: it was late.

@eht16 eht16 changed the title "Too many #ifdef configurations" in Debugger plugin Debugger plugin: potential cppcheck false positive: uninitvar Oct 14, 2020
@elextr
Copy link
Member

elextr commented Oct 14, 2020

Maybe restructure the widgets loop as a for() and cppcheck might recognise it better?

eht16 added a commit to eht16/geany-plugins that referenced this issue Oct 17, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
eht16 added a commit to eht16/geany-plugins that referenced this issue Oct 17, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
@eht16
Copy link
Member Author

eht16 commented Oct 17, 2020

Maybe restructure the widgets loop as a for() and cppcheck might recognise it better?

Tried but didn't help and would be even worse as you first need to know the array size.
#1017 fixes the cppcheck warning which actually seems to be a false positive, cppcheck gets confused about the pointer dereferencing.

eht16 added a commit to eht16/geany-plugins that referenced this issue Oct 19, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
eht16 added a commit to eht16/geany-plugins that referenced this issue Oct 24, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
eht16 added a commit to eht16/geany-plugins that referenced this issue Oct 24, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
eht16 added a commit that referenced this issue Oct 24, 2020
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes #1014.
eshcom pushed a commit to eshcom/geany-plugins that referenced this issue Jan 28, 2025
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants