Skip to content

Commit

Permalink
disable format-truncation warning for testing truncating format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Mar 4, 2025
1 parent b94ea71 commit b38e552
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/test_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,22 @@ TORRENT_TEST(error_code)
#pragma GCC diagnostic ignored "-Wformat-truncation="
#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-truncation"
#endif

TORRENT_TEST(snprintf)
{
char msg[10];
std::snprintf(msg, sizeof(msg), "too %s format string", "long");
TEST_CHECK(strcmp(msg, "too long ") == 0);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#if defined __GNUC__ && __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
Expand Down Expand Up @@ -171,6 +180,11 @@ TORRENT_TEST(printf_uint64)
#pragma GCC diagnostic ignored "-Wformat-truncation="
#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-truncation"
#endif

TORRENT_TEST(printf_trunc)
{
char buffer[4];
Expand All @@ -179,6 +193,10 @@ TORRENT_TEST(printf_trunc)
TEST_EQUAL(buffer, std::string("184"));
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#if defined __GNUC__ && __GNUC__ >= 7
#pragma GCC diagnostic pop
#endif
Expand Down

0 comments on commit b38e552

Please sign in to comment.