Skip to content

Commit 3006ff8

Browse files
derekmaurocopybara-github
authored andcommitted
Use a proper fix instead of a workaround for a parameter annotated
absl_nonnull since the latest Clang can see through the workaround PiperOrigin-RevId: 764428456 Change-Id: I88398f924333a72abb39ffb87ecbd02f751d89eb
1 parent 8a5cefc commit 3006ff8

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

absl/strings/str_format_test.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,11 @@ TEST_F(FormatEntryPointTest, SNPrintF) {
516516
EXPECT_EQ(result, 17);
517517
EXPECT_EQ(std::string(buffer), "NUMBER: 1234567");
518518

519-
// The `output` parameter is annotated nonnull, but we want to test that
520-
// it is never written to if the size is zero.
521-
// Use a variable instead of passing nullptr directly to avoid a `-Wnonnull`
522-
// warning.
523-
char* null_output = nullptr;
524-
result =
525-
SNPrintF(null_output, 0, "Just checking the %s of the output.", "size");
519+
// Test that the buffer is never written to if the size is zero.
520+
buffer[0] = '\0';
521+
result = SNPrintF(buffer, 0, "Just checking the %s of the output.", "size");
526522
EXPECT_EQ(result, 37);
523+
EXPECT_EQ(buffer[0], '\0');
527524
}
528525

529526
TEST_F(FormatEntryPointTest, SNPrintFWithV) {
@@ -551,14 +548,11 @@ TEST_F(FormatEntryPointTest, SNPrintFWithV) {
551548

552549
std::string size = "size";
553550

554-
// The `output` parameter is annotated nonnull, but we want to test that
555-
// it is never written to if the size is zero.
556-
// Use a variable instead of passing nullptr directly to avoid a `-Wnonnull`
557-
// warning.
558-
char* null_output = nullptr;
559-
result =
560-
SNPrintF(null_output, 0, "Just checking the %v of the output.", size);
551+
// Test that the buffer is never written to if the size is zero.
552+
buffer[0] = '\0';
553+
result = SNPrintF(buffer, 0, "Just checking the %v of the output.", size);
561554
EXPECT_EQ(result, 37);
555+
EXPECT_EQ(buffer[0], '\0');
562556
}
563557

564558
TEST(StrFormat, BehavesAsDocumented) {

0 commit comments

Comments
 (0)