]> granicus.if.org Git - strace/commitdiff
Macroize conditional signed widening operation
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 15 Feb 2013 13:58:52 +0000 (14:58 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 15 Feb 2013 13:58:52 +0000 (14:58 +0100)
* defs.h: Define widen_to_long() macro.
* signal.c (sys_kill): Use it instead of open-coding it.
(sys_tgkill): Use widen_to_long() on pids.
* resource.c (decode_rlimit): Formatting fix.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
defs.h
resource.c
signal.c

diff --git a/defs.h b/defs.h
index 7702aaed29d5aee2c6a75cdf674a022144b45117..c607dfd707dfd1b73bb14011362616924a344f10 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -723,6 +723,16 @@ extern unsigned current_wordsize;
 # endif
 #endif
 
+/* In many, many places we play fast and loose and use
+ * tprintf("%d", (int) tcp->u_arg[N]) to print fds, pids etc.
+ * We probably need to use widen_to_long() instead:
+ */
+#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
+# define widen_to_long(v) (current_wordsize == 4 ? (long)(int32_t)(v) : (long)(v))
+#else
+# define widen_to_long(v) ((long)(v))
+#endif
+
 struct sysent {
        unsigned nargs;
        int     sys_flags;
index 5a51d8cb3a84c2a721d5a61211e310ab44bf361d..657e63de4ad103c0ff49413e72739b69348e3b40 100644 (file)
@@ -173,8 +173,7 @@ decode_rlimit(struct tcb *tcp, unsigned long addr)
 {
        if (!addr)
                tprints("NULL");
-       else if (!verbose(tcp) ||
-                (exiting(tcp) && syserror(tcp)))
+       else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
                tprintf("%#lx", addr);
        else {
 # if SIZEOF_RLIM_T == 4
index 55ff3ed743ffc840c6cec5d7d587473fb3cf2416..11d49d334b37dbcbe537842ffa2074ddad43a10d 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -1117,13 +1117,10 @@ int
 sys_kill(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               long pid = tcp->u_arg[0];
-#if SUPPORTED_PERSONALITIES > 1
-               /* Sign-extend a 32-bit value when that's what it is. */
-               if (current_wordsize < sizeof pid)
-                       pid = (long) (int) pid;
-#endif
-               tprintf("%ld, %s", pid, signame(tcp->u_arg[1]));
+               tprintf("%ld, %s",
+                       widen_to_long(tcp->u_arg[0]),
+                       signame(tcp->u_arg[1])
+               );
        }
        return 0;
 }
@@ -1133,7 +1130,10 @@ sys_tgkill(struct tcb *tcp)
 {
        if (entering(tcp)) {
                tprintf("%ld, %ld, %s",
-                       tcp->u_arg[0], tcp->u_arg[1], signame(tcp->u_arg[2]));
+                       widen_to_long(tcp->u_arg[0]),
+                       widen_to_long(tcp->u_arg[1]),
+                       signame(tcp->u_arg[2])
+               );
        }
        return 0;
 }