]> granicus.if.org Git - strace/commitdiff
tests/futex: add support to sprintrc for return codes other than 0 and -1
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 2 Sep 2016 15:27:18 +0000 (18:27 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 2 Sep 2016 17:21:14 +0000 (17:21 +0000)
* tests/futex.c (sprintrc): Print the actual return code provided,
not just "0".  Check snprintf return code.

tests/futex.c

index 28d9df87e34773bd9b70999a65fcbef47111c9ff..09a6c25c4cf931bce99bf626f01e28b2ceec05ba 100644 (file)
@@ -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;
 }