Skip to content

Commit

Permalink
Fix FreeBSD build with GCC
Browse files Browse the repository at this point in the history
Apparently FreeBSD's GCC defines NULL to 0 in C++11 mode and this causes
the following error:
```
In file included from capsicum-test.h:15,
                 from capsicum-test.cc:1:
gtest-1.10.0/include/gtest/gtest.h: In instantiation of 'testing::AssertionResult testing::internal::CmpHelperNE(const char*, const char*, const T1&, const T2&) [with T1 = long int; T2 = procstat*]':
capsicum-test.cc:75:3:   required from here
gtest-1.10.0/include/gtest/gtest.h:1621:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
 1609 |   if (val1 op val2) {\
      |       ~~~~~~~~~~~~
......
 1621 | GTEST_IMPL_CMP_HELPER_(NE, !=);
gtest-1.10.0/include/gtest/gtest.h:1609:12: note: in definition of macro 'GTEST_IMPL_CMP_HELPER_'
 1609 |   if (val1 op val2) {\
      |            ^~
```

Fix this by using nullptr directly.
  • Loading branch information
arichardson authored and daviddrysdale committed Mar 4, 2021
1 parent f4d9741 commit a7e466e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions capsicum-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ char ProcessState(int pid) {
}
unsigned int count = 0;
struct procstat *prstat = procstat_open_sysctl();
EXPECT_NE(NULL, prstat) << "procstat_open_sysctl failed.";
EXPECT_NE(nullptr, prstat) << "procstat_open_sysctl failed.";
errno = 0;
struct kinfo_proc *p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &count);
if (p == NULL || count == 0) {
if (verbose) fprintf(stderr, "procstat_getprocs failed with %p/%d: %s\n", p, count, strerror(errno));
if (verbose) {
fprintf(stderr, "procstat_getprocs failed with %p/%d: %s\n", (void *)p,
count, strerror(errno));
}
procstat_close(prstat);
return '\0';
}
Expand Down

0 comments on commit a7e466e

Please sign in to comment.