]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.407 v7.3.407
authorBram Moolenaar <Bram@vim.org>
Fri, 20 Jan 2012 19:44:43 +0000 (20:44 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 20 Jan 2012 19:44:43 +0000 (20:44 +0100)
Problem:    ":12verbose call F()" may duplicate text while trying to truncate.
            (Thinca)
Solution:   Only truncate when there is not enough room.  Also check the byte
            length of the buffer.

src/buffer.c
src/eval.c
src/ex_getln.c
src/message.c
src/proto/message.pro
src/version.c

index 2884b30381e8ea99a5b50f21bc3fd3c6907ba16e..8cf5f8ac00540aa59d0e5de600df94bac364eb2c 100644 (file)
@@ -3258,9 +3258,8 @@ maketitle()
            if (maxlen > 0)
            {
                /* make it shorter by removing a bit in the middle */
-               len = vim_strsize(buf);
-               if (len > maxlen)
-                   trunc_string(buf, buf, maxlen);
+               if (vim_strsize(buf) > maxlen)
+                   trunc_string(buf, buf, maxlen, IOSIZE);
            }
        }
     }
index 16e740f6de9ea1420e8203a6ef3320a5c4de154d..dd1685106fac48376ba8edc9b6691c79bce5d76c 100644 (file)
@@ -22163,8 +22163,12 @@ call_user_func(fp, argcount, argvars, rettv, firstline, lastline, selfdict)
                        s = tv2string(&argvars[i], &tofree, numbuf2, 0);
                        if (s != NULL)
                        {
-                           trunc_string(s, buf, MSG_BUF_CLEN);
-                           msg_puts(buf);
+                           if (vim_strsize(s) > MSG_BUF_CLEN)
+                           {
+                               trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
+                               s = buf;
+                           }
+                           msg_puts(s);
                            vim_free(tofree);
                        }
                    }
@@ -22252,8 +22256,12 @@ call_user_func(fp, argcount, argvars, rettv, firstline, lastline, selfdict)
            s = tv2string(fc->rettv, &tofree, numbuf2, 0);
            if (s != NULL)
            {
-               trunc_string(s, buf, MSG_BUF_CLEN);
-               smsg((char_u *)_("%s returning %s"), sourcing_name, buf);
+               if (vim_strsize(s) > MSG_BUF_CLEN)
+               {
+                   trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
+                   s = buf;
+               }
+               smsg((char_u *)_("%s returning %s"), sourcing_name, s);
                vim_free(tofree);
            }
        }
index 97f8305abab1dff54197fdbbf97d712e916f4aad..b63ebb613773195b5b20dfe65f62cac50f049418 100644 (file)
@@ -5923,7 +5923,7 @@ ex_history(eap)
                                                              hist[i].hisnum);
                    if (vim_strsize(hist[i].hisstr) > (int)Columns - 10)
                        trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff),
-                                                          (int)Columns - 10);
+                                 (int)Columns - 10, IOSIZE - STRLEN(IObuff));
                    else
                        STRCAT(IObuff, hist[i].hisstr);
                    msg_outtrans(IObuff);
index 03a7ea534bb64d12d21b8d54acfbe7b46f09efbb..95f626c95df29bc0bb727a25d1831789e6af20ca 100644 (file)
@@ -222,15 +222,16 @@ msg_strtrunc(s, force)
            if (enc_utf8)
                /* may have up to 18 bytes per cell (6 per char, up to two
                 * composing chars) */
-               buf = alloc((room + 2) * 18);
+               len = (room + 2) * 18;
            else if (enc_dbcs == DBCS_JPNU)
                /* may have up to 2 bytes per cell for euc-jp */
-               buf = alloc((room + 2) * 2);
+               len = (room + 2) * 2;
            else
 #endif
-               buf = alloc(room + 2);
+               len = room + 2;
+           buf = alloc(len);
            if (buf != NULL)
-               trunc_string(s, buf, room);
+               trunc_string(s, buf, room, len);
        }
     }
     return buf;
@@ -241,10 +242,11 @@ msg_strtrunc(s, force)
  * "s" and "buf" may be equal.
  */
     void
-trunc_string(s, buf, room)
+trunc_string(s, buf, room, buflen)
     char_u     *s;
     char_u     *buf;
     int                room;
+    int                buflen;
 {
     int                half;
     int                len;
@@ -257,7 +259,7 @@ trunc_string(s, buf, room)
     len = 0;
 
     /* First part: Start of the string. */
-    for (e = 0; len < half; ++e)
+    for (e = 0; len < half && e < buflen; ++e)
     {
        if (s[e] == NUL)
        {
@@ -274,7 +276,8 @@ trunc_string(s, buf, room)
        if (has_mbyte)
            for (n = (*mb_ptr2len)(s + e); --n > 0; )
            {
-               ++e;
+               if (++e == buflen)
+                   break;
                buf[e] = s[e];
            }
 #endif
@@ -319,8 +322,19 @@ trunc_string(s, buf, room)
     }
 
     /* Set the middle and copy the last part. */
-    mch_memmove(buf + e, "...", (size_t)3);
-    STRMOVE(buf + e + 3, s + i);
+    if (e + 3 < buflen)
+    {
+       mch_memmove(buf + e, "...", (size_t)3);
+       len = STRLEN(s + i) + 1;
+       if (len >= buflen - e - 3)
+           len = buflen - e - 3 - 1;
+       mch_memmove(buf + e + 3, s + i, len);
+       buf[e + 3 + len - 1] = NUL;
+    }
+    else
+    {
+       buf[e - 1] = NUL;  // make sure it is truncated
+    }
 }
 
 /*
index c59a9165f42aada1ae223cdecfc6e9af661aa18b..a12f1200c758550f2d1c0cd3f0aa77593cc9ba78 100644 (file)
@@ -4,7 +4,7 @@ int verb_msg __ARGS((char_u *s));
 int msg_attr __ARGS((char_u *s, int attr));
 int msg_attr_keep __ARGS((char_u *s, int attr, int keep));
 char_u *msg_strtrunc __ARGS((char_u *s, int force));
-void trunc_string __ARGS((char_u *s, char_u *buf, int room));
+void trunc_string __ARGS((char_u *s, char_u *buf, int room, int buflen));
 void reset_last_sourcing __ARGS((void));
 void msg_source __ARGS((int attr));
 int emsg_not_now __ARGS((void));
index 0b281a5de91beb1f5fce0441659cab4bc402e38f..ccd583bebaccb96dde83e87fefd89cb2239e1d05 100644 (file)
@@ -714,6 +714,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    407,
 /**/
     406,
 /**/