]> granicus.if.org Git - strace/commitdiff
Change length type of umoven and umovestr to unsigned
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 14 Jan 2015 08:05:45 +0000 (08:05 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 14 Jan 2015 13:18:05 +0000 (13:18 +0000)
* defs.h (umoven, umovestr): Change type of 3rd argument from "int"
to "unsigned int".
* util.c (umoven, umovestr): Likewise.  Adjust the code appropriately.

defs.h
util.c

diff --git a/defs.h b/defs.h
index ad6eefd44982eb8ffc18e4a116d6275bdaba8d26..03162176a5bfb0fc773db1aeed75534f2e29ae10 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -639,10 +639,10 @@ extern void get_regs(pid_t pid);
 # define clear_regs()  ((void)0)
 # define get_regs(pid) ((void)0)
 #endif
-extern int umoven(struct tcb *, long, int, char *);
+extern int umoven(struct tcb *, long, unsigned int, char *);
 #define umove(pid, addr, objp) \
        umoven((pid), (addr), sizeof(*(objp)), (char *) (objp))
-extern int umovestr(struct tcb *, long, int, char *);
+extern int umovestr(struct tcb *, long, unsigned int, char *);
 extern int upeek(int pid, long, long *);
 #if defined(SPARC) || defined(SPARC64) || defined(IA64) || defined(SH)
 extern long getrval2(struct tcb *);
diff --git a/util.c b/util.c
index c7ad34f16d5aab112a7502fb5a630402aa15b2dd..3b50191d9b7adf3ef9e570736afd16fcb97b386d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -929,10 +929,10 @@ static bool process_vm_readv_not_supported = 1;
  * at address `addr' to our space at `laddr'
  */
 int
-umoven(struct tcb *tcp, long addr, int len, char *laddr)
+umoven(struct tcb *tcp, long addr, unsigned int len, char *laddr)
 {
        int pid = tcp->pid;
-       int n, m, nread;
+       unsigned int n, m, nread;
        union {
                long val;
                char x[sizeof(long)];
@@ -951,11 +951,11 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
                remote[0].iov_base = (void*)addr;
                local[0].iov_len = remote[0].iov_len = len;
                r = process_vm_readv(pid, local, 1, remote, 1, 0);
-               if (r == len)
+               if ((unsigned int) r == len)
                        return 0;
                if (r >= 0) {
-                       error_msg("umoven: short read (%d < %d) @0x%lx",
-                                 r, len, addr);
+                       error_msg("umoven: short read (%u < %u) @0x%lx",
+                                 (unsigned int) r, len, addr);
                        return -1;
                }
                switch (errno) {
@@ -978,8 +978,8 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
        nread = 0;
        if (addr & (sizeof(long) - 1)) {
                /* addr not a multiple of sizeof(long) */
-               n = addr - (addr & -sizeof(long)); /* residue */
-               addr &= -sizeof(long); /* residue */
+               n = addr & (sizeof(long) - 1);  /* residue */
+               addr &= -sizeof(long);          /* aligned address */
                errno = 0;
                u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
                switch (errno) {
@@ -1016,7 +1016,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
                        case EFAULT: case EIO: case EPERM:
                                /* address space is inaccessible */
                                if (nread) {
-                                       perror_msg("umoven: short read (%d < %d) @0x%lx",
+                                       perror_msg("umoven: short read (%u < %u) @0x%lx",
                                                   nread, nread + len, addr - nread);
                                }
                                return -1;
@@ -1050,7 +1050,7 @@ umoven(struct tcb *tcp, long addr, int len, char *laddr)
  * we never write past laddr[len-1]).
  */
 int
-umovestr(struct tcb *tcp, long addr, int len, char *laddr)
+umovestr(struct tcb *tcp, long addr, unsigned int len, char *laddr)
 {
 #if SIZEOF_LONG == 4
        const unsigned long x01010101 = 0x01010101ul;
@@ -1063,7 +1063,7 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
 #endif
 
        int pid = tcp->pid;
-       int n, m, nread;
+       unsigned int n, m, nread;
        union {
                unsigned long val;
                char x[sizeof(long)];
@@ -1082,9 +1082,9 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
                remote[0].iov_base = (void*)addr;
 
                while (len > 0) {
-                       int end_in_page;
+                       unsigned int chunk_len;
+                       unsigned int end_in_page;
                        int r;
-                       int chunk_len;
 
                        /* Don't read kilobytes: most strings are short */
                        chunk_len = len;
@@ -1096,9 +1096,8 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
                         * (I hope there aren't arches with pages < 4K)
                         */
                        end_in_page = ((addr + chunk_len) & 4095);
-                       r = chunk_len - end_in_page;
-                       if (r > 0) /* if chunk_len > end_in_page */
-                               chunk_len = r; /* chunk_len -= end_in_page */
+                       if (chunk_len > end_in_page) /* crosses to the next page */
+                               chunk_len -= end_in_page;
 
                        local[0].iov_len = remote[0].iov_len = chunk_len;
                        r = process_vm_readv(pid, local, 1, remote, 1, 0);
@@ -1137,8 +1136,8 @@ umovestr(struct tcb *tcp, long addr, int len, char *laddr)
 
        if (addr & (sizeof(long) - 1)) {
                /* addr not a multiple of sizeof(long) */
-               n = addr - (addr & -sizeof(long)); /* residue */
-               addr &= -sizeof(long); /* residue */
+               n = addr & (sizeof(long) - 1);  /* residue */
+               addr &= -sizeof(long);          /* aligned address */
                errno = 0;
                u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
                switch (errno) {