LSC: Fix null safety issues diagnosed by Clang’s -Wnonnull and -Wnullability.

**Note**: These changes are generated by hand. Review with care.

This CL changes the `absl_internal` implementations of `AsciiStrToLower()` /
`AsciiStrToUpper()` to allow `src` to be null. This can, in fact, happen if the
`string_view` passed to the public API is empty, and the implementations handle
it correctly. I have added comments noting that `src` is allowed to be null
iff the size is zero.

`-Wnonnull` diagnoses cases where a `nullptr` literal is passed to a parameter
annotated nonnull, or where `nullptr` is returned from a function whose return
type is annotated nonnull.

`-Wnullability` diagnoses cases where nullability annotations conflict, for
example between the declaration and definition of a function.

PiperOrigin-RevId: 673846759
Change-Id: I6cf3490ce13837eba9814156c420598000ecc596
This commit is contained in:
Martin Brænne
2024-09-12 07:56:09 -07:00
committed by Copybara-Service
parent a1a7086ead
commit f555f69ba8
5 changed files with 50 additions and 10 deletions

View File

@@ -516,7 +516,13 @@ TEST_F(FormatEntryPointTest, SNPrintF) {
EXPECT_EQ(result, 17);
EXPECT_EQ(std::string(buffer), "NUMBER: 1234567");
result = SNPrintF(nullptr, 0, "Just checking the %s of the output.", "size");
// The `output` parameter is annotated nonnull, but we want to test that
// it is never written to if the size is zero.
// Use a variable instead of passing nullptr directly to avoid a `-Wnonnull`
// warning.
char* null_output = nullptr;
result =
SNPrintF(null_output, 0, "Just checking the %s of the output.", "size");
EXPECT_EQ(result, 37);
}
@@ -545,7 +551,13 @@ TEST_F(FormatEntryPointTest, SNPrintFWithV) {
std::string size = "size";
result = SNPrintF(nullptr, 0, "Just checking the %v of the output.", size);
// The `output` parameter is annotated nonnull, but we want to test that
// it is never written to if the size is zero.
// Use a variable instead of passing nullptr directly to avoid a `-Wnonnull`
// warning.
char* null_output = nullptr;
result =
SNPrintF(null_output, 0, "Just checking the %v of the output.", size);
EXPECT_EQ(result, 37);
}