Fix clang-tidy bugprone-string-literal-with-embedded-nul warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-17 12:44:25 -07:00
parent 74acc30258
commit 02589c349a
3 changed files with 4 additions and 0 deletions

View file

@ -9,4 +9,5 @@ Checks: [-*,
bugprone-inc-dec-in-conditions, bugprone-inc-dec-in-conditions,
bugprone-misplaced-widening-cast, bugprone-misplaced-widening-cast,
bugprone-parent-virtual-call, bugprone-parent-virtual-call,
bugprone-string-literal-with-embedded-nul,
] ]

View file

@ -167,6 +167,7 @@ TEST_CASE("fmt_mac") {
CHECK(my_fmt_mac("", 0) == ""); CHECK(my_fmt_mac("", 0) == "");
CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06", 4) == ""); CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06", 4) == "");
CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06", 6) == "01:02:03:04:05:06"); CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06", 6) == "01:02:03:04:05:06");
// NOLINTNEXTLINE(bugprone-string-literal-with-embedded-nul)
CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06\x00\x00", 8) == "01:02:03:04:05:06"); CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06\x00\x00", 8) == "01:02:03:04:05:06");
CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06\x07\x08", 8) == "01:02:03:04:05:06:07:08"); CHECK(my_fmt_mac("\x01\x02\x03\x04\x05\x06\x07\x08", 8) == "01:02:03:04:05:06:07:08");
CHECK(my_fmt_mac("\x08\x07\x06\x05\x04\x03\x02\x01", 8) == "08:07:06:05:04:03:02:01"); CHECK(my_fmt_mac("\x08\x07\x06\x05\x04\x03\x02\x01", 8) == "08:07:06:05:04:03:02:01");
@ -191,6 +192,7 @@ TEST_CASE("fmt_mac_bytes") {
CHECK(len2 == 2 * 6 + 5); CHECK(len2 == 2 * 6 + 5);
CHECK(memcmp(buf2.get(), "01:02:03:04:05:06", len2 + 1) == 0); CHECK(memcmp(buf2.get(), "01:02:03:04:05:06", len2 + 1) == 0);
// NOLINTNEXTLINE(bugprone-string-literal-with-embedded-nul)
auto [buf3, len3] = my_fmt_mac_bytes("\x01\x02\x03\x04\x05\x06\x00\x00", 8); auto [buf3, len3] = my_fmt_mac_bytes("\x01\x02\x03\x04\x05\x06\x00\x00", 8);
CHECK(len3 == 2 * 6 + 5); CHECK(len3 == 2 * 6 + 5);
CHECK(memcmp(buf3.get(), "01:02:03:04:05:06", len3 + 1) == 0); CHECK(memcmp(buf3.get(), "01:02:03:04:05:06", len3 + 1) == 0);

View file

@ -2336,6 +2336,7 @@ TEST_CASE("util json_escape_utf8") {
// Valid ASCII and valid ASCII control characters // Valid ASCII and valid ASCII control characters
CHECK(json_escape_utf8("a") == "a"); CHECK(json_escape_utf8("a") == "a");
// NOLINTNEXTLINE(bugprone-string-literal-with-embedded-nul)
CHECK(json_escape_utf8("\b\f\n\r\t\x00\x15") == "\b\f\n\r\t\x00\x15"); CHECK(json_escape_utf8("\b\f\n\r\t\x00\x15") == "\b\f\n\r\t\x00\x15");
// Table 3-7 in https://www.unicode.org/versions/Unicode12.0.0/ch03.pdf describes what is // Table 3-7 in https://www.unicode.org/versions/Unicode12.0.0/ch03.pdf describes what is