]> granicus.if.org Git - strace/commitdiff
Fix explicit casts of signed integer types to unsigned long long
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 26 May 2016 10:12:17 +0000 (10:12 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 26 May 2016 14:44:13 +0000 (14:44 +0000)
* defs.h (widen_to_ull): New macro.
* dirent.c (print_old_dirent, SYS_FUNC(getdents)): Use it in place
of explicit casts to unsigned long long.
* io.c (print_lld_from_low_high_val): Likewise.
* lseek.c (SYS_FUNC(llseek)): Likewise.
* printsiginfo.c (print_si_info): Likewise.
* printstat.h (DO_PRINTSTAT): Likewise.
* sysinfo.c (SYS_FUNC(sysinfo)): Likewise.
* times.c (SYS_FUNC(times)): Likewise.
* fetch_struct_statfs.c (ASSIGN_NUMBER): Remove.
(fetch_struct_statfs, fetch_struct_statfs64): Replace ASSIGN_NUMBER
with widen_to_ull.

defs.h
dirent.c
fetch_struct_statfs.c
io.c
lseek.c
printsiginfo.c
printstat.h
sysinfo.c
times.c

diff --git a/defs.h b/defs.h
index ceb535a1ed97441961b176e3645d1b5c141e5025..d72f5c252e8403c9d824335d37fb46c534a1da24 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -770,6 +770,14 @@ extern unsigned current_wordsize;
 # define widen_to_long(v) ((long)(v))
 #endif
 
+/*
+ * Widen without sign-extension a signed integer type to unsigned long long.
+ */
+#define widen_to_ull(v) \
+       (sizeof(v) == sizeof(int) ? (unsigned long long) (unsigned int) (v) : \
+        sizeof(v) == sizeof(long) ? (unsigned long long) (unsigned long) (v) : \
+        (unsigned long long) (v))
+
 extern const struct_sysent sysent0[];
 extern const char *const errnoent0[];
 extern const char *const signalent0[];
index 7d882ae2d1afb564553987ec635abc55df6f5408..75e36355da257c0e9654aa39c9202a3bc275fc28 100644 (file)
--- a/dirent.c
+++ b/dirent.c
@@ -48,8 +48,8 @@ print_old_dirent(struct tcb *tcp, long addr)
                return;
 
        tprintf("{d_ino=%llu, d_off=%llu, d_reclen=%u, d_name=",
-               (unsigned long long) d.d_ino,
-               (unsigned long long) d.d_off, d.d_reclen);
+               widen_to_ull(d.d_ino),
+               widen_to_ull(d.d_off), d.d_reclen);
        if (d.d_reclen > D_NAME_LEN_MAX)
                d.d_reclen = D_NAME_LEN_MAX;
        printpathn(tcp, addr + offsetof(kernel_dirent, d_name), d.d_reclen);
@@ -127,8 +127,8 @@ SYS_FUNC(getdents)
 
                        tprintf("%s{d_ino=%llu, d_off=%llu, d_reclen=%u"
                                ", d_name=", i ? ", " : "",
-                               (unsigned long long) d->d_ino,
-                               (unsigned long long) d->d_off, d->d_reclen);
+                               widen_to_ull(d->d_ino),
+                               widen_to_ull(d->d_off), d->d_reclen);
 
                        if (print_quoted_string(d->d_name, d_name_len,
                                                QUOTE_0_TERMINATED) > 0) {
index 0717e4b2d9d6f2b921039c2ca8b234dda6ac1519..0cfe5bafc0272bba72517e603ac6f9dfb3b8dde2 100644 (file)
@@ -39,14 +39,6 @@ typedef struct statfs64 struct_statfs64;
 
 #include "statfs.h"
 
-#define ASSIGN_NUMBER(dst, src)                                \
-       if (sizeof(src) == sizeof(int))                 \
-               dst = (unsigned int) (src);             \
-       else if (sizeof(src) == sizeof(long))           \
-               dst = (unsigned long) (src);            \
-       else                                            \
-               dst = (unsigned long long) (src)
-
 MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
                   struct tcb *tcp, const long addr, struct strace_statfs *p)
 {
@@ -55,26 +47,26 @@ MPERS_PRINTER_DECL(bool, fetch_struct_statfs,
        if (umove_or_printaddr(tcp, addr, &b))
                return false;
 
-       ASSIGN_NUMBER(p->f_type, b.f_type);
-       ASSIGN_NUMBER(p->f_bsize, b.f_bsize);
-       ASSIGN_NUMBER(p->f_blocks, b.f_blocks);
-       ASSIGN_NUMBER(p->f_bfree, b.f_bfree);
-       ASSIGN_NUMBER(p->f_bavail, b.f_bavail);
-       ASSIGN_NUMBER(p->f_files, b.f_files);
-       ASSIGN_NUMBER(p->f_ffree, b.f_ffree);
+       p->f_type = widen_to_ull(b.f_type);
+       p->f_bsize = widen_to_ull(b.f_bsize);
+       p->f_blocks = widen_to_ull(b.f_blocks);
+       p->f_bfree = widen_to_ull(b.f_bfree);
+       p->f_bavail = widen_to_ull(b.f_bavail);
+       p->f_files = widen_to_ull(b.f_files);
+       p->f_ffree = widen_to_ull(b.f_ffree);
 #if defined HAVE_STRUCT_STATFS_F_FSID_VAL
-       ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.val[0]);
-       ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.val[1]);
+       p->f_fsid[0] = widen_to_ull(b.f_fsid.val[0]);
+       p->f_fsid[1] = widen_to_ull(b.f_fsid.val[1]);
 #elif defined HAVE_STRUCT_STATFS_F_FSID___VAL
-       ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.__val[0]);
-       ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.__val[1]);
+       p->f_fsid[0] = widen_to_ull(b.f_fsid.__val[0]);
+       p->f_fsid[1] = widen_to_ull(b.f_fsid.__val[1]);
 #endif
-       ASSIGN_NUMBER(p->f_namelen, b.f_namelen);
+       p->f_namelen = widen_to_ull(b.f_namelen);
 #ifdef HAVE_STRUCT_STATFS_F_FRSIZE
-       ASSIGN_NUMBER(p->f_frsize, b.f_frsize);
+       p->f_frsize = widen_to_ull(b.f_frsize);
 #endif
 #ifdef HAVE_STRUCT_STATFS_F_FLAGS
-       ASSIGN_NUMBER(p->f_flags, b.f_flags);
+       p->f_flags = widen_to_ull(b.f_flags);
 #endif
 
        return true;
@@ -103,26 +95,26 @@ MPERS_PRINTER_DECL(bool, fetch_struct_statfs64,
        if (umove_or_printaddr(tcp, addr, &b))
                return false;
 
-       ASSIGN_NUMBER(p->f_type, b.f_type);
-       ASSIGN_NUMBER(p->f_bsize, b.f_bsize);
-       ASSIGN_NUMBER(p->f_blocks, b.f_blocks);
-       ASSIGN_NUMBER(p->f_bfree, b.f_bfree);
-       ASSIGN_NUMBER(p->f_bavail, b.f_bavail);
-       ASSIGN_NUMBER(p->f_files, b.f_files);
-       ASSIGN_NUMBER(p->f_ffree, b.f_ffree);
+       p->f_type = widen_to_ull(b.f_type);
+       p->f_bsize = widen_to_ull(b.f_bsize);
+       p->f_blocks = widen_to_ull(b.f_blocks);
+       p->f_bfree = widen_to_ull(b.f_bfree);
+       p->f_bavail = widen_to_ull(b.f_bavail);
+       p->f_files = widen_to_ull(b.f_files);
+       p->f_ffree = widen_to_ull(b.f_ffree);
 #if defined HAVE_STRUCT_STATFS64_F_FSID_VAL
-       ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.val[0]);
-       ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.val[1]);
+       p->f_fsid[0] = widen_to_ull(b.f_fsid.val[0]);
+       p->f_fsid[1] = widen_to_ull(b.f_fsid.val[1]);
 #elif defined HAVE_STRUCT_STATFS64_F_FSID___VAL
-       ASSIGN_NUMBER(p->f_fsid[0], b.f_fsid.__val[0]);
-       ASSIGN_NUMBER(p->f_fsid[1], b.f_fsid.__val[1]);
+       p->f_fsid[0] = widen_to_ull(b.f_fsid.__val[0]);
+       p->f_fsid[1] = widen_to_ull(b.f_fsid.__val[1]);
 #endif
-       ASSIGN_NUMBER(p->f_namelen, b.f_namelen);
+       p->f_namelen = widen_to_ull(b.f_namelen);
 #ifdef HAVE_STRUCT_STATFS64_F_FRSIZE
-       ASSIGN_NUMBER(p->f_frsize, b.f_frsize);
+       p->f_frsize = widen_to_ull(b.f_frsize);
 #endif
 #ifdef HAVE_STRUCT_STATFS64_F_FLAGS
-       ASSIGN_NUMBER(p->f_flags, b.f_flags);
+       p->f_flags = widen_to_ull(b.f_flags);
 #endif
 
        return true;
diff --git a/io.c b/io.c
index 3c4ef592f1d376c3f176ad8a8cbbf778040c7083..87b5f47f4feee35998abce59f47ca2e3cc1c40b7 100644 (file)
--- a/io.c
+++ b/io.c
@@ -202,8 +202,8 @@ print_lld_from_low_high_val(struct tcb *tcp, int arg)
        else
 # endif
        tprintf("%lld",
-               ((unsigned long long) (unsigned long) tcp->u_arg[arg + 1] << sizeof(long) * 8)
-               | (unsigned long long) (unsigned long) tcp->u_arg[arg]);
+               (widen_to_ull(tcp->u_arg[arg + 1]) << sizeof(long) * 8)
+               | widen_to_ull(tcp->u_arg[arg]));
 #endif
 }
 
diff --git a/lseek.c b/lseek.c
index cfc6b586e9675b33167a6a629f328cbecd084cce..133ddd853bda373bc38726b607ceb8348f8d36f8 100644 (file)
--- a/lseek.c
+++ b/lseek.c
@@ -108,8 +108,8 @@ SYS_FUNC(llseek)
        if (entering(tcp)) {
                printfd(tcp, tcp->u_arg[0]);
                tprintf(", %lld, ",
-                       ((unsigned long long) (unsigned long) tcp->u_arg[1]) << 32
-                       | (unsigned long long) (unsigned long) tcp->u_arg[2]);
+                       (widen_to_ull(tcp->u_arg[1]) << 32)
+                       | widen_to_ull(tcp->u_arg[2]));
        } else {
                printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64);
                tprints(", ");
index a14ebb49012452d6997fb1f31a93d233712ffdb3..98755b28fec33b5c26acb29620315001d61f706f 100644 (file)
@@ -171,8 +171,8 @@ print_si_info(const siginfo_t *sip)
                        else
                                printsignal(sip->si_status);
                        tprintf(", si_utime=%llu, si_stime=%llu",
-                               (unsigned long long) sip->si_utime,
-                               (unsigned long long) sip->si_stime);
+                               widen_to_ull(sip->si_utime),
+                               widen_to_ull(sip->si_stime));
                        break;
                case SIGILL: case SIGFPE:
                case SIGSEGV: case SIGBUS:
index c7e1bb22c4467ac0345f46b0d84b4606e72376c2..5bf745c5f6478d47ce01eee16d359f9143c7ae1e 100644 (file)
@@ -55,7 +55,7 @@ DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
                tprintf("{st_dev=makedev(%u, %u), st_ino=%llu, st_mode=%s, ",
                        (unsigned int) STAT_MAJOR(statbuf->st_dev),
                        (unsigned int) STAT_MINOR(statbuf->st_dev),
-                       (unsigned long long) statbuf->st_ino,
+                       widen_to_ull(statbuf->st_ino),
                        sprintmode(statbuf->st_mode));
                tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
                        (unsigned int) statbuf->st_nlink,
@@ -65,8 +65,7 @@ DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
                tprintf("st_blksize=%u, ", (unsigned int) statbuf->st_blksize);
 #endif
 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
-               tprintf("st_blocks=%llu, ",
-                       (unsigned long long) statbuf->st_blocks);
+               tprintf("st_blocks=%llu, ", widen_to_ull(statbuf->st_blocks));
 #endif
        } else {
                tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
@@ -85,8 +84,7 @@ DO_PRINTSTAT(struct tcb *tcp, const STRUCT_STAT *statbuf)
 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
                break;
        default:
-               tprintf("st_size=%llu, ",
-                       (unsigned long long) statbuf->st_size);
+               tprintf("st_size=%llu, ", widen_to_ull(statbuf->st_size));
                break;
        }
 
index e418f95c4c3d4f87d72374f4f5e1290bc09acded..c3cb9adcbe4cb5d7d9786711df427e31ffe99bbd 100644 (file)
--- a/sysinfo.c
+++ b/sysinfo.c
@@ -59,19 +59,19 @@ SYS_FUNC(sysinfo)
                        ", freehigh=%llu"
                        ", mem_unit=%u"
                        "}",
-                       (unsigned long long) si.uptime
-                       , (unsigned long long) si.loads[0]
-                       , (unsigned long long) si.loads[1]
-                       , (unsigned long long) si.loads[2]
-                       , (unsigned long long) si.totalram
-                       , (unsigned long long) si.freeram
-                       , (unsigned long long) si.sharedram
-                       , (unsigned long long) si.bufferram
-                       , (unsigned long long) si.totalswap
-                       , (unsigned long long) si.freeswap
+                       widen_to_ull(si.uptime)
+                       , widen_to_ull(si.loads[0])
+                       , widen_to_ull(si.loads[1])
+                       , widen_to_ull(si.loads[2])
+                       , widen_to_ull(si.totalram)
+                       , widen_to_ull(si.freeram)
+                       , widen_to_ull(si.sharedram)
+                       , widen_to_ull(si.bufferram)
+                       , widen_to_ull(si.totalswap)
+                       , widen_to_ull(si.freeswap)
                        , (unsigned) si.procs
-                       , (unsigned long long) si.totalhigh
-                       , (unsigned long long) si.freehigh
+                       , widen_to_ull(si.totalhigh)
+                       , widen_to_ull(si.freehigh)
                        , si.mem_unit
                        );
        }
diff --git a/times.c b/times.c
index d3f6daf25152f4e4a83987c4364f4c02cc77141e..04df462e277f2c1edd756bc5a020fb4bba69fd61 100644 (file)
--- a/times.c
+++ b/times.c
@@ -46,11 +46,11 @@ SYS_FUNC(times)
 
        if (!umove_or_printaddr(tcp, tcp->u_arg[0], &tbuf)) {
                tprintf("{tms_utime=%llu, tms_stime=%llu, ",
-                       (unsigned long long) tbuf.tms_utime,
-                       (unsigned long long) tbuf.tms_stime);
+                       widen_to_ull(tbuf.tms_utime),
+                       widen_to_ull(tbuf.tms_stime));
                tprintf("tms_cutime=%llu, tms_cstime=%llu}",
-                       (unsigned long long) tbuf.tms_cutime,
-                       (unsigned long long) tbuf.tms_cstime);
+                       widen_to_ull(tbuf.tms_cutime),
+                       widen_to_ull(tbuf.tms_cstime));
        }
 
        return syserror(tcp) ? RVAL_DECIMAL :