From 1bbed69059d5ac35c0775e8ed598a34628d8ba6d Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 17 Jul 2020 17:29:20 -0700 Subject: [PATCH] [sanitizer] Another attempt to fix protoent test Now we are going to pick name and index based on output of getprotoent_r. --- .../sanitizer_common/TestCases/Linux/protoent.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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; }