diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp index a10fd114022c..003790067d1b 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp @@ -7,6 +7,10 @@ #include #include #include +#include + +std::string any_name; +int total_count; void print_protoent(protoent *curr_entry) { fprintf(stderr, "%s (%d)\n", curr_entry->p_name, curr_entry->p_proto); @@ -23,6 +27,8 @@ void print_all_protoent() { protoent *curr_entry; while (getprotoent_r(&entry, buf, sizeof(buf), &curr_entry) != ENOENT && curr_entry) { + ++total_count; + any_name = curr_entry->p_name; print_protoent(curr_entry); } } @@ -51,10 +57,13 @@ int main() { fprintf(stderr, "All protoent\n"); print_all_protoent(); + if (!total_count) + return 0; + fprintf(stderr, "Protoent by name\n"); - print_protoent_by_name("ipv6"); + print_protoent_by_name(any_name.c_str()); fprintf(stderr, "Protoent by num\n"); - print_protoent_by_num(17); + print_protoent_by_num(total_count / 2); return 0; }