htop icon indicating copy to clipboard operation
htop copied to clipboard

NetBSD compile warning ("potential null pointer dereference")

Open Explorer09 opened this issue 8 months ago • 4 comments

This warning is when building htop for NetBSD, with GCC with -flto enabled

lto-wrapper: warning: using serial compilation of 3 LTRANS jobs
DisplayOptionsPanel.c: In function ‘DisplayOptionsPanel_eventHandler’:
DisplayOptionsPanel.c:98:14: error: potential null pointer dereference [-Werror=null-dereference]
   98 |          if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
      |              ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: gcc returned 1 exit status

I actually caught this one in CI (build log), and yet I don't know how to fix it at the moment.

Explorer09 avatar Apr 06 '25 17:04 Explorer09

NetBSD or OpenBSD?

BenBE avatar Apr 06 '25 20:04 BenBE

@BenBE Sorry, it's NetBSD, not OpenBSD. I corrected the description.

Explorer09 avatar Apr 06 '25 20:04 Explorer09

The problem is likely selected == NULL, which can be returned from Panel_getSelected(super); in line 91, propagating to line 98 through the fall-thru case …

Modifying line 92 to read if (previous != selected || !selected) { should address this. /untested

BenBE avatar Apr 06 '25 21:04 BenBE

@Explorer09 Can you take a look at this suggestion and do a PR if you like?

BenBE avatar Apr 22 '25 10:04 BenBE