Skip to content

Commit af8e0e8

Browse files
Copilotdthaler
andcommitted
Address PR comments: remove redundant checks and unnecessary nullptr checks
Co-authored-by: dthaler <[email protected]>
1 parent 8ca6e63 commit af8e0e8

File tree

1 file changed

+17
-52
lines changed

1 file changed

+17
-52
lines changed

tests/api_test/api_test.cpp

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,6 @@ TEST_CASE("ebpf_type_conversion_apis", "[ebpf_api]")
16441644
const char* retrieved_name = ebpf_get_program_type_name(&program_type);
16451645
REQUIRE(retrieved_name != nullptr);
16461646
REQUIRE(std::string(retrieved_name) == "bind");
1647-
REQUIRE(strlen(retrieved_name) > 0);
16481647
}
16491648

16501649
// Test path canonicalization API.
@@ -1697,9 +1696,7 @@ TEST_CASE("ebpf_enumerate_programs", "[ebpf_api]")
16971696
}
16981697

16991698
// Clean up error message if any.
1700-
if (error_message != nullptr) {
1701-
ebpf_free_string(error_message);
1702-
}
1699+
ebpf_free_string(error_message);
17031700
}
17041701

17051702
// Test with non-existent file - should fail gracefully.
@@ -1709,9 +1706,7 @@ TEST_CASE("ebpf_enumerate_programs", "[ebpf_api]")
17091706
REQUIRE(result != EBPF_SUCCESS);
17101707

17111708
// Clean up error message if any.
1712-
if (error_message != nullptr) {
1713-
ebpf_free_string(error_message);
1714-
}
1709+
ebpf_free_string(error_message);
17151710
}
17161711

17171712
// Test eBPF verification APIs.
@@ -1740,12 +1735,8 @@ TEST_CASE("ebpf_verification_apis", "[ebpf_api]")
17401735
REQUIRE(result == 0);
17411736

17421737
// Clean up strings.
1743-
if (report != nullptr) {
1744-
ebpf_free_string(report);
1745-
}
1746-
if (error_message != nullptr) {
1747-
ebpf_free_string(error_message);
1748-
}
1738+
ebpf_free_string(report);
1739+
ebpf_free_string(error_message);
17491740
}
17501741

17511742
// Test disassembly APIs.
@@ -1767,12 +1758,8 @@ TEST_CASE("ebpf_verification_apis", "[ebpf_api]")
17671758
}
17681759

17691760
// Clean up strings.
1770-
if (disassembly != nullptr) {
1771-
ebpf_free_string(disassembly);
1772-
}
1773-
if (error_message != nullptr) {
1774-
ebpf_free_string(error_message);
1775-
}
1761+
ebpf_free_string(disassembly);
1762+
ebpf_free_string(error_message);
17761763
}
17771764
}
17781765

@@ -2053,9 +2040,7 @@ TEST_CASE("ebpf_enumerate_sections_deprecated", "[ebpf_api]")
20532040
}
20542041

20552042
// Clean up error message if any.
2056-
if (error_message != nullptr) {
2057-
ebpf_free_string(error_message);
2058-
}
2043+
ebpf_free_string(error_message);
20592044
}
20602045

20612046
// Test deprecated ebpf_get_next_pinned_program_path API.
@@ -2097,25 +2082,17 @@ TEST_CASE("ebpf_verification_memory_apis", "[ebpf_api]")
20972082
REQUIRE(result != 0); // Not successful verification.
20982083

20992084
// Clean up strings.
2100-
if (report != nullptr) {
2101-
ebpf_free_string(report);
2102-
}
2103-
if (error_message != nullptr) {
2104-
ebpf_free_string(error_message);
2105-
}
2085+
ebpf_free_string(report);
2086+
ebpf_free_string(error_message);
21062087

21072088
// Test with null data - should fail gracefully.
21082089
result = ebpf_api_elf_verify_program_from_memory(
21092090
nullptr, 0, nullptr, nullptr, nullptr, EBPF_VERIFICATION_VERBOSITY_NORMAL, &report, &error_message, &stats);
21102091
REQUIRE(result != 0);
21112092

21122093
// Clean up strings.
2113-
if (report != nullptr) {
2114-
ebpf_free_string(report);
2115-
}
2116-
if (error_message != nullptr) {
2117-
ebpf_free_string(error_message);
2118-
}
2094+
ebpf_free_string(report);
2095+
ebpf_free_string(error_message);
21192096
}
21202097

21212098
// Test remaining deprecated eBPF verification APIs for completeness.
@@ -2136,12 +2113,8 @@ TEST_CASE("ebpf_deprecated_verification_apis", "[ebpf_api]")
21362113
}
21372114

21382115
// Clean up strings.
2139-
if (disassembly != nullptr) {
2140-
ebpf_free_string(disassembly);
2141-
}
2142-
if (error_message != nullptr) {
2143-
ebpf_free_string(error_message);
2144-
}
2116+
ebpf_free_string(disassembly);
2117+
ebpf_free_string(error_message);
21452118

21462119
// Test deprecated verify section from file API.
21472120
const char* report = nullptr;
@@ -2160,12 +2133,8 @@ TEST_CASE("ebpf_deprecated_verification_apis", "[ebpf_api]")
21602133
#pragma warning(pop)
21612134

21622135
// Clean up strings.
2163-
if (report != nullptr) {
2164-
ebpf_free_string(report);
2165-
}
2166-
if (error_message != nullptr) {
2167-
ebpf_free_string(error_message);
2168-
}
2136+
ebpf_free_string(report);
2137+
ebpf_free_string(error_message);
21692138

21702139
// Test deprecated verify section from memory API.
21712140
const char* test_data = "minimal_test_data";
@@ -2187,10 +2156,6 @@ TEST_CASE("ebpf_deprecated_verification_apis", "[ebpf_api]")
21872156
REQUIRE(result != 0); // Not successful verification.
21882157

21892158
// Clean up strings.
2190-
if (report != nullptr) {
2191-
ebpf_free_string(report);
2192-
}
2193-
if (error_message != nullptr) {
2194-
ebpf_free_string(error_message);
2195-
}
2159+
ebpf_free_string(report);
2160+
ebpf_free_string(error_message);
21962161
}

0 commit comments

Comments
 (0)