zombieCraig / UDSim

GNU General Public License v3.0
288 stars 95 forks source link

Build Error in logparser.cc #7

Open Loris1123 opened 2 years ago

Loris1123 commented 2 years ago

I got the following build error when building UDSim on my Arch Linux:

logparser.cc: In member function ‘std::string LogParser::processNext()’:
logparser.cc:36:14: error: ordered comparison of pointer with integer zero (‘FILE*’ and ‘int’)
   36 |     if(logfp < 0) {
      |        ~~~~~~^~~
make: *** [Makefile:17: logparser.o] Error 1

To fix the issue I changed the corrensponding line to

if(logfp != 0) {

Keep in mind I'm not a C programmer and don't know if that is the way, this issue should be fixed. But for me it works :-)

bhass1 commented 1 year ago

@Loris1123 - Yes, that will work, although arguably better for readability to use if(logfp != NULL) {

2018 POSIX spec for fopen says: "Upon successful completion, fopen() shall return a pointer to the object controlling the stream. Otherwise, a null pointer shall be returned, and errno shall be set to indicate the error."

Looks like that was also the behavior of fopen in POSIX.1-2001. Not sure what changed since this code was released, but this is a good fix that should be mainlined.