From: Eugene Syromyatnikov Date: Fri, 2 Sep 2016 15:27:18 +0000 (+0300) Subject: tests/futex: add support to sprintrc for return codes other than 0 and -1 X-Git-Tag: v4.14~131 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bb9f473e44dc75f3462b9d9753ae3bfa309b1a9;p=strace tests/futex: add support to sprintrc for return codes other than 0 and -1 * tests/futex.c (sprintrc): Print the actual return code provided, not just "0". Check snprintf return code. --- diff --git a/tests/futex.c b/tests/futex.c index 28d9df87..09a6c25c 100644 --- a/tests/futex.c +++ b/tests/futex.c @@ -150,7 +150,15 @@ const char *sprintrc(long rc) if (rc == 0) return "0"; - snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()); + int ret = (rc == -1) + ? snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name()) + : snprintf(buf, sizeof(buf), "%ld", rc); + + if (ret < 0) + perror_msg_and_fail("snprintf"); + if ((size_t) ret >= sizeof(buf)) + error_msg_and_fail("snprintf overflow: got %d, expected " + "no more than %zu", ret, sizeof(buf)); return buf; }