Skip to content

Commit

Permalink
Stop using assert() outside test code
Browse files Browse the repository at this point in the history
This is because in cases where the code is compiled with NDEBUG defined,
we could have unsafe behavior. Instead of relying on assert, we check
the return value of this function in the callers.
  • Loading branch information
horgh committed Nov 2, 2023
1 parent 30853b1 commit e714886
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* The feature test macro `_POSIX_C_SOURCE` is no longer set by
`maxminddb.h`. As discussed in GitHub #318, this should be set by
applications rather than by libraries.
* `assert()` is no longer used outside test code.

## 1.7.1 - 2022-09-30

Expand Down
6 changes: 3 additions & 3 deletions src/maxminddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "data-pool.h"
#include "maxminddb-compat-util.h"
#include "maxminddb.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
Expand Down Expand Up @@ -993,10 +992,11 @@ static record_info_s record_info_for_database(const MMDB_s *const mmdb) {
record_info.left_record_getter = &get_uint32;
record_info.right_record_getter = &get_uint32;
record_info.right_record_offset = 4;
} else {
assert(false);
}

// Callers must check that right_record_offset is non-zero in case none of
// the above conditions matched.

return record_info;
}

Expand Down

0 comments on commit e714886

Please sign in to comment.