zabbix-module-systemd
zabbix-module-systemd copied to clipboard
gcc9 complaining about comparison between pointer and zero character constant
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)
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 thanks for the explanation. I'll submit a PR tomorrow.