zabbix-module-systemd icon indicating copy to clipboard operation
zabbix-module-systemd copied to clipboard

gcc9 complaining about comparison between pointer and zero character constant

Open mjtrangoni opened this issue 5 years ago • 2 comments

Hi @cavaliercoder,

gcc[1] reports this warning,

libzbxsystemd.c: In function ‘SYSTEMD_UNIT_DISCOVERY’:
libzbxsystemd.c:214:35: warning: comparison between pointer and zero character constant [-Wpointer-compare]
  214 |         if(NULL != filter || '\0' != filter)
      |                                   ^~
libzbxsystemd.c:214:38: note: did you mean to dereference the pointer?
  214 |         if(NULL != filter || '\0' != filter)
      |                                      ^

Why do you need to check that in parallel to the correspondent NULL?

[1] gcc (GCC) 9.3.1 20200317 (Red Hat 9.3.1-1)

mjtrangoni avatar Apr 02 '20 14:04 mjtrangoni

gcc[1] reports this warning

...and rightly so!

Why do you need to check that in parallel to the correspondent NULL?

It should have been '\0' != *filter, which would be a check for empty string. Strings is C are null-terminated, i.e. null character '\0' marks the end of the string. *string is the same as string[0]. If the first character of the string is null-character, then the string is empty.

@mjtrangoni, would you like to create a pull request? I'm sure @cavaliercoder or @jangaraj will be happy to merge it.

i-ky avatar Apr 02 '20 18:04 i-ky

@i-ky thanks for the explanation. I'll submit a PR tomorrow.

mjtrangoni avatar Apr 02 '20 18:04 mjtrangoni