]> granicus.if.org Git - strace/commitdiff
Cleanup fetch part of printstr_ex
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Nov 2016 16:33:37 +0000 (16:33 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 19 Nov 2016 16:33:37 +0000 (16:33 +0000)
* util.c (printstr_ex): Initialize "style" early, unify error handling.

util.c

diff --git a/util.c b/util.c
index c75b64cd494968093d2fbe30d456574132d854ef..54a77e699d95a1177614d05fc448c5bc4e113564 100644 (file)
--- a/util.c
+++ b/util.c
@@ -836,7 +836,8 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style)
        static char *str = NULL;
        static char *outstr;
        unsigned int size;
-       unsigned int style;
+       unsigned int style = user_style;
+       int rc;
        int ellipsis;
 
        if (!addr) {
@@ -859,24 +860,18 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style)
                 * Treat as a NUL-terminated string: fetch one byte more
                 * because string_quote may look one byte ahead.
                 */
-               if (umovestr(tcp, addr, size, str) < 0) {
-                       printaddr(addr);
-                       return;
-               }
-               style = QUOTE_0_TERMINATED;
+               style |= QUOTE_0_TERMINATED;
+               rc = umovestr(tcp, addr, size, str);
+       } else {
+               if (size > (unsigned long) len)
+                       size = (unsigned long) len;
+               rc = umoven(tcp, addr, size, str);
        }
-       else {
-               if (size > (unsigned long)len)
-                       size = (unsigned long)len;
-               if (umoven(tcp, addr, size, str) < 0) {
-                       printaddr(addr);
-                       return;
-               }
-               style = 0;
+       if (rc < 0) {
+               printaddr(addr);
+               return;
        }
 
-       style |= user_style;
-
        if (style & QUOTE_0_TERMINATED) {
                if (size) {
                        --size;