[PATCH v2 3/5] tests/futex: Add support for return codes other than 0 and -1 to sprintrc
Eugene Syromyatnikov
evgsyr at gmail.com
Fri Sep 2 15:27:18 UTC 2016
* tests/futex.c (sprintrc): Print the actual return code provided, not
just "0"; checks for snprintf return code added.
---
tests/futex.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tests/futex.c b/tests/futex.c
index 28d9df8..09a6c25 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;
}
--
1.7.10.4
More information about the Strace-devel
mailing list