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

Stop using assert outside test code #324

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 8 additions & 5 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 @@ -929,7 +928,7 @@ static int find_address_in_search_tree(const MMDB_s *const mmdb,
sa_family_t address_family,
MMDB_lookup_result_s *result) {
record_info_s record_info = record_info_for_database(mmdb);
if (0 == record_info.right_record_offset) {
if (record_info.right_record_offset == 0) {
return MMDB_UNKNOWN_DATABASE_FORMAT_ERROR;
}

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 All @@ -1009,6 +1009,9 @@ static int find_ipv4_start_node(MMDB_s *const mmdb) {
}

record_info_s record_info = record_info_for_database(mmdb);
if (record_info.right_record_offset == 0) {
return MMDB_UNKNOWN_DATABASE_FORMAT_ERROR;
}

const uint8_t *search_tree = mmdb->file_content;
uint32_t node_value = 0;
Expand Down Expand Up @@ -1071,7 +1074,7 @@ int MMDB_read_node(const MMDB_s *const mmdb,
uint32_t node_number,
MMDB_search_node_s *const node) {
record_info_s record_info = record_info_for_database(mmdb);
if (0 == record_info.right_record_offset) {
if (record_info.right_record_offset == 0) {
return MMDB_UNKNOWN_DATABASE_FORMAT_ERROR;
}

Expand Down
Loading