]> granicus.if.org Git - strace/commitdiff
Replace widen_to_ulong with truncate_kulong_to_current_wordsize
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 26 Dec 2016 17:47:55 +0000 (17:47 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 26 Dec 2016 17:47:55 +0000 (17:47 +0000)
* defs.h (widen_to_ulong): Remove.
(truncate_kulong_to_current_wordsize): New static inline function.
* io.c (do_preadv, do_pwritev): Use it instead of widen_to_ulong.

defs.h
io.c

diff --git a/defs.h b/defs.h
index 6591ba899c306a9ff494021bb15e5a07ffa0eb1e..d6155a8e13ea73b67b0cefb74d05110c35bdcc25 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -871,13 +871,19 @@ DECL_PRINTPAIR(int64);
 # define widen_to_long(v) ((long)(v))
 #endif
 
-#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
-# define widen_to_ulong(v) \
-       (current_wordsize == 4 ? (unsigned long) (uint32_t) (v) : \
-               (unsigned long) (v))
-#else
-# define widen_to_ulong(v) ((unsigned long)(v))
-#endif
+static inline kernel_ulong_t
+truncate_kulong_to_current_wordsize(const kernel_ulong_t v)
+{
+#if SIZEOF_KERNEL_LONG_T > 4 \
+ && (SIZEOF_LONG < SIZEOF_KERNEL_LONG_T || !defined current_wordsize)
+       if (current_wordsize < sizeof(v)) {
+               return (unsigned int) v;
+       } else
+#endif
+       {
+               return v;
+       }
+}
 
 /*
  * Cast a pointer or a pointer-sized integer to kernel_ulong_t.
diff --git a/io.c b/io.c
index 94dcf88bedb5e139dd82ca85e749f73bb74c34f8..c41b66fa26f0d0d8493fbd3c59b33312543e3bac 100644 (file)
--- a/io.c
+++ b/io.c
@@ -203,12 +203,13 @@ do_preadv(struct tcb *tcp, const int flags_arg)
                printfd(tcp, tcp->u_arg[0]);
                tprints(", ");
        } else {
-               unsigned long len = widen_to_ulong(tcp->u_arg[2]);
+               kernel_ulong_t len =
+                       truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
 
                tprint_iov_upto(tcp, len, tcp->u_arg[1],
                                syserror(tcp) ? IOV_DECODE_ADDR :
                                IOV_DECODE_STR, tcp->u_rval);
-               tprintf(", %lu, ", len);
+               tprintf(", %" PRI_klu ", ", len);
                print_lld_from_low_high_val(tcp, 3);
                if (flags_arg >= 0) {
                        tprints(", ");
@@ -231,12 +232,13 @@ SYS_FUNC(preadv2)
 static int
 do_pwritev(struct tcb *tcp, const int flags_arg)
 {
-       unsigned long len = widen_to_ulong(tcp->u_arg[2]);
+       kernel_ulong_t len =
+               truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
 
        printfd(tcp, tcp->u_arg[0]);
        tprints(", ");
        tprint_iov(tcp, len, tcp->u_arg[1], IOV_DECODE_STR);
-       tprintf(", %lu, ", len);
+       tprintf(", %" PRI_klu ", ", len);
        print_lld_from_low_high_val(tcp, 3);
        if (flags_arg >= 0) {
                tprints(", ");