Skip to content

Commit 1bbed69

Browse files
committed
[sanitizer] Another attempt to fix protoent test
Now we are going to pick name and index based on output of getprotoent_r.
1 parent b0a971d commit 1bbed69

File tree

1 file changed

+11
-2
lines changed
  • compiler-rt/test/sanitizer_common/TestCases/Linux

1 file changed

+11
-2
lines changed

compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <errno.h>
88
#include <netdb.h>
99
#include <stdio.h>
10+
#include <string>
11+
12+
std::string any_name;
13+
int total_count;
1014

1115
void print_protoent(protoent *curr_entry) {
1216
fprintf(stderr, "%s (%d)\n", curr_entry->p_name, curr_entry->p_proto);
@@ -23,6 +27,8 @@ void print_all_protoent() {
2327
protoent *curr_entry;
2428

2529
while (getprotoent_r(&entry, buf, sizeof(buf), &curr_entry) != ENOENT && curr_entry) {
30+
++total_count;
31+
any_name = curr_entry->p_name;
2632
print_protoent(curr_entry);
2733
}
2834
}
@@ -51,10 +57,13 @@ int main() {
5157
fprintf(stderr, "All protoent\n");
5258
print_all_protoent();
5359

60+
if (!total_count)
61+
return 0;
62+
5463
fprintf(stderr, "Protoent by name\n");
55-
print_protoent_by_name("ipv6");
64+
print_protoent_by_name(any_name.c_str());
5665

5766
fprintf(stderr, "Protoent by num\n");
58-
print_protoent_by_num(17);
67+
print_protoent_by_num(total_count / 2);
5968
return 0;
6069
}

0 commit comments

Comments
 (0)