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

gcc9 complaining about comparison between pointer and zero character constant #44

Open
mjtrangoni opened this issue Apr 2, 2020 · 2 comments · May be fixed by #45
Open

gcc9 complaining about comparison between pointer and zero character constant #44

mjtrangoni opened this issue Apr 2, 2020 · 2 comments · May be fixed by #45

Comments

@mjtrangoni
Copy link

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)

@i-ky
Copy link

i-ky commented Apr 2, 2020

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.

@mjtrangoni
Copy link
Author

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

mjtrangoni added a commit to mjtrangoni/zabbix-module-systemd that referenced this issue Apr 3, 2020
Fix zabbix-tools#44

See,
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)
      |

Signed-off-by: Mario Trangoni <[email protected]>
mjtrangoni added a commit to mjtrangoni/zabbix-module-systemd that referenced this issue Apr 3, 2020
Fix zabbix-tools#44

See,
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)
      |

Signed-off-by: Mario Trangoni <[email protected]>
mjtrangoni added a commit to mjtrangoni/zabbix-module-systemd that referenced this issue Apr 3, 2020
Fix zabbix-tools#44

See,
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)
      |

Signed-off-by: Mario Trangoni <[email protected]>
mjtrangoni added a commit to mjtrangoni/zabbix-module-systemd that referenced this issue Apr 3, 2020
Fix zabbix-tools#44

See,
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)
      |

Signed-off-by: Mario Trangoni <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants