Skip to content

Commit

Permalink
Only use clang pragmas on clang
Browse files Browse the repository at this point in the history
So that we don't need to disable them everywhere else.
  • Loading branch information
oschwald committed Nov 3, 2023
1 parent 9517c89 commit 5c22ca1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang-analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- run: ./bootstrap
- run: scan-build ./configure
env:
CFLAGS: -std=c99 -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -Wno-unknown-pragmas
CFLAGS: -std=c99 -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter
- run: cd src; scan-build --status-bugs make; cd ..
- run: cd bin; scan-build --status-bugs make; cd ..
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ jobs:
- run: ./bootstrap
- run: ./configure
env:
# -Wno-unknown-pragmas because we have some Clang specific pragmas
# which aren't interesting to cause failures for.
CFLAGS: -std=c99 -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -Wno-unknown-pragmas ${{ matrix.posix }}
CFLAGS: -std=c99 -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter ${{ matrix.posix }}
- run: make
- run: make check

Expand Down
24 changes: 24 additions & 0 deletions src/maxminddb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,12 +1815,16 @@ static void free_mmdb_struct(MMDB_s *const mmdb) {
}

if (NULL != mmdb->filename) {
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
FREE_AND_SET_NULL(mmdb->filename);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
if (NULL != mmdb->file_content) {
#ifdef _WIN32
Expand All @@ -1829,22 +1833,30 @@ static void free_mmdb_struct(MMDB_s *const mmdb) {
* to cleanup then. */
WSACleanup();
#else
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
munmap((void *)mmdb->file_content, (size_t)mmdb->file_size);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif
}

if (NULL != mmdb->metadata.database_type) {
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
FREE_AND_SET_NULL(mmdb->metadata.database_type);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}

free_languages_metadata(mmdb);
Expand All @@ -1857,12 +1869,16 @@ static void free_languages_metadata(MMDB_s *mmdb) {
}

for (size_t i = 0; i < mmdb->metadata.languages.count; i++) {
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
FREE_AND_SET_NULL(mmdb->metadata.languages.names[i]);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
FREE_AND_SET_NULL(mmdb->metadata.languages.names);
}
Expand All @@ -1875,24 +1891,32 @@ static void free_descriptions_metadata(MMDB_s *mmdb) {
for (size_t i = 0; i < mmdb->metadata.description.count; i++) {
if (NULL != mmdb->metadata.description.descriptions[i]) {
if (NULL != mmdb->metadata.description.descriptions[i]->language) {
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
FREE_AND_SET_NULL(
mmdb->metadata.description.descriptions[i]->language);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}

if (NULL !=
mmdb->metadata.description.descriptions[i]->description) {
#if defined(__clang__)
// This is a const char * that we need to free, which isn't valid. However it
// would mean changing the public API to fix this.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
FREE_AND_SET_NULL(
mmdb->metadata.description.descriptions[i]->description);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
FREE_AND_SET_NULL(mmdb->metadata.description.descriptions[i]);
}
Expand Down
4 changes: 4 additions & 0 deletions t/maxminddb_test_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ void for_all_record_sizes(const char *filename_fmt,
int size = sizes[i];

char filename[500];
#if defined(__clang__)
// This warning seems ok to ignore here in the tests.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(filename, 500, filename_fmt, size);
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

char description[14];
snprintf(description, 14, "%i bit record", size);
Expand Down

0 comments on commit 5c22ca1

Please sign in to comment.