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

comparison between pointer and zero #1760

Closed
abishai opened this issue Jan 31, 2017 · 9 comments
Closed

comparison between pointer and zero #1760

abishai opened this issue Jan 31, 2017 · 9 comments
Labels

Comments

@abishai
Copy link
Contributor

abishai commented Jan 31, 2017

ZoneMinder can't be compiled with CLANG 4.0 It bumped severity of such comparison to error.
src/zm_monitor.cpp contains comparison between (unsigned char*) mem_ptr and 0 in several places.

src/zm_monitor.cpp:197:18: error: ordered comparison between pointer and zero
('unsigned char *' and 'int')
    if ( mem_ptr > 0 )
	 ~~~~~~~ ^ ~
@connortechnology
Copy link
Member

The line should probably like this:
if ( mem_ptr > (void *)0 ) {

@abishai
Copy link
Contributor Author

abishai commented Feb 2, 2017

Maybe, !=0 is OK too.

@connortechnology
Copy link
Member

No because failure to mmap results in -1.

@abishai
Copy link
Contributor Author

abishai commented Feb 3, 2017

I added fix to my FreeBSD PR. Compiles on my test system with your fix.

@mastertheknife
Copy link
Contributor

What about comparing it to NULL?
NULL is typically defined as (void*)0, so mem_ptr > NULL should work.

JiangXL added a commit to JiangXL/micro-manager that referenced this issue Aug 9, 2017
When I try to compile Micro-manager, I trouble into `  ordered comparison between pointer and zero ('usb_dev_handle *' and 'int')`. Then I find same error in [here](ZoneMinder/zoneminder#1760). It work. 


Error: 


Making all in USBManager
make[2]: Entering directory '/home/igem/Downloads/mm/micro-manager/DeviceAdapters/USBManager'
/bin/sh ../libtool  --tag=CXX   --mode=compile clang++ -DPACKAGE_NAME=\"Micro-Manager\" -DPACKAGE_TARNAME=\"micro-manager\" -DPACKAGE_VERSION=\"1.4\" -DPACKAGE_STRING=\"Micro-Manager\ 1.4\" -DPACKAGE_BUGREPORT=\"info@micro-manager.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"micro-manager\" -DVERSION=\"1.4\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_BOOST=/\*\*/ -DHAVE_BOOST_THREAD=/\*\*/ -DHAVE_BOOST_ASIO=/\*\*/ -DHAVE_BOOST_SYSTEM=/\*\*/ -DHAVE_BOOST_CHRONO=/\*\*/ -DHAVE_BOOST_DATE_TIME=/\*\*/ -DHAVE__BOOL=1 -DHAVE_STDBOOL_H=1 -DSTDC_HEADERS=1 -DHAVE_MEMSET=1 -I.  -I/usr/include/libusb-1.0  -I/home/igem/Downloads/mm/micro-manager/DeviceAdapters/../MMDevice -pthread -I/usr/include  -g -O2 -MT USBManager.lo -MD -MP -MF .deps/USBManager.Tpo -c -o USBManager.lo USBManager.cpp
libtool: compile:  clang++ -DPACKAGE_NAME=\"Micro-Manager\" -DPACKAGE_TARNAME=\"micro-manager\" -DPACKAGE_VERSION=\"1.4\" "-DPACKAGE_STRING=\"Micro-Manager 1.4\"" -DPACKAGE_BUGREPORT=\"info@micro-manager.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"micro-manager\" -DVERSION=\"1.4\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" "-DHAVE_BOOST=/**/" "-DHAVE_BOOST_THREAD=/**/" "-DHAVE_BOOST_ASIO=/**/" "-DHAVE_BOOST_SYSTEM=/**/" "-DHAVE_BOOST_CHRONO=/**/" "-DHAVE_BOOST_DATE_TIME=/**/" -DHAVE__BOOL=1 -DHAVE_STDBOOL_H=1 -DSTDC_HEADERS=1 -DHAVE_MEMSET=1 -I. -I/usr/include/libusb-1.0 -I/home/igem/Downloads/mm/micro-manager/DeviceAdapters/../MMDevice -pthread -I/usr/include -g -O2 -MT USBManager.lo -MD -MP -MF .deps/USBManager.Tpo -c USBManager.cpp  -fPIC -DPIC -o .libs/USBManager.o
USBManager.cpp:284:34: error: ordered comparison between pointer and zero ('usb_dev_handle *' and 'int')
               if (deviceHandle_ <= 0)
                   ~~~~~~~~~~~~~ ^  ~
1 error generated.
make[2]: *** [Makefile:524: USBManager.lo] Error 1
make[2]: Leaving directory '/home/igem/Downloads/mm/micro-manager/DeviceAdapters/USBManager'
make[1]: *** [Makefile:615: all-recursive] Error 1
make[1]: Leaving directory '/home/igem/Downloads/mm/micro-manager/DeviceAdapters'
make: *** [Makefile:518: all-recursive] Error 1
@arvidn
Copy link

arvidn commented Nov 1, 2017

for the record, mmap() returns MAP_FAILED on error (which may or may not be the same value as (void*)-1). posix spec.

@connortechnology
Copy link
Member

It seems like we should follow posix.. defined constants are both readable... and defined.. hence... good.. Mmkay?

@stale
Copy link

stale bot commented Jun 15, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 15, 2018
@stale stale bot closed this as completed Jun 22, 2018
@ali-babaei
Copy link

The line should probably like this:
if ( mem_ptr > (void *)0 ) {

on:
Telegram Android Client

I had following error:

jni/./gifvideo.cpp:151:28: error: ordered comparison between pointer and zero ('AVStream *' and 'int')
if (info->video_stream <= 0) {
~~~~~~~~~~~~~~~~~~ ^ ~

Thanks @connortechnology, your solution worked for me too.

Just commented here for everybody facing this issue later!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants