]> granicus.if.org Git - strace/commitdiff
2007-08-01 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Thu, 2 Aug 2007 02:06:26 +0000 (02:06 +0000)
committerRoland McGrath <roland@redhat.com>
Thu, 2 Aug 2007 02:06:26 +0000 (02:06 +0000)
* util.c (printstr): Don't print ... if the string matches the length
limit exactly.

util.c

diff --git a/util.c b/util.c
index 64210ef9b0320f71b97b68d2c339940d68775ca2..5855c10acb92ca63bec141f63c0e7023eea6b3a0 100644 (file)
--- a/util.c
+++ b/util.c
@@ -442,13 +442,14 @@ int len;
        static char *outstr;
        int i, n, c, usehex;
        char *s, *outend;
+       int trunc;
 
        if (!addr) {
                tprintf("NULL");
                return;
        }
        if (!str) {
-               if ((str = malloc(max_strlen)) == NULL
+               if ((str = malloc(max_strlen + 1)) == NULL
                    || (outstr = malloc(4*max_strlen
                                        + sizeof "\"\"...")) == NULL) {
                        fprintf(stderr, "out of memory\n");
@@ -458,20 +459,22 @@ int len;
        }
        outend = outstr + max_strlen * 4;
        if (len < 0) {
-               n = max_strlen;
+               n = max_strlen + 1;
                if (umovestr(tcp, addr, n, (char *) str) < 0) {
                        tprintf("%#lx", addr);
                        return;
                }
        }
        else {
-               n = MIN(len, max_strlen);
+               n = MIN(len, max_strlen + 1);
                if (umoven(tcp, addr, n, (char *) str) < 0) {
                        tprintf("%#lx", addr);
                        return;
                }
        }
 
+       trunc = n > max_strlen && str[--n] != 0;
+
        usehex = 0;
        if (xflag > 1)
                usehex = 1;
@@ -538,7 +541,7 @@ int len;
        }
 
        *s++ = '\"';
-       if (i < len || (len < 0 && (i == n || s > outend))) {
+       if (i < len || (len < 0 && (trunc || s > outend))) {
                *s++ = '.'; *s++ = '.'; *s++ = '.';
        }
        *s = '\0';