Skip to content

Commit 3392ff3

Browse files
committed
better errors
Created using spr 1.3.4
1 parent 7871fb4 commit 3392ff3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,37 @@
44

55
#include <arpa/inet.h>
66
#include <assert.h>
7+
#include <errno.h>
78
#include <netdb.h>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
13+
void CheckResult(int ret) {
14+
if (ret != 0) {
15+
fprintf(stderr, "%s\n", strerror(errno));
16+
abort();
17+
}
18+
}
819

920
int main(void) {
1021
struct servent result_buf;
1122
struct servent *result;
1223
char buf[1024];
13-
assert(getservent_r(&result_buf, buf, sizeof(buf), &result) == 0);
24+
CheckResult(getservent_r(&result_buf, buf, sizeof(buf), &result));
1425
assert(result != nullptr);
1526

1627
// If these fail, check /etc/services if "ssh" exists. I picked this because
1728
// it should exist everywhere, if it doesn't, I am sorry. Disable the test
1829
// then please.
19-
assert(getservbyname_r("ssh", nullptr, &result_buf, buf, sizeof(buf),
20-
&result) == 0);
30+
CheckResult(
31+
getservbyname_r("ssh", nullptr, &result_buf, buf, sizeof(buf), &result));
2132
assert(result != nullptr);
22-
assert(getservbyport_r(htons(22), nullptr, &result_buf, buf, sizeof(buf),
23-
&result) == 0);
33+
CheckResult(getservbyport_r(htons(22), nullptr, &result_buf, buf, sizeof(buf),
34+
&result));
2435
assert(result != nullptr);
2536

26-
assert(getservbyname_r("invalidhadfuiasdhi", nullptr, &result_buf, buf,
27-
sizeof(buf), &result) == 0);
37+
CheckResult(getservbyname_r("invalidhadfuiasdhi", nullptr, &result_buf, buf,
38+
sizeof(buf), &result));
2839
assert(result == nullptr);
2940
}

0 commit comments

Comments
 (0)