comparison src/popupmenu.c @ 18667:de350001150c v8.1.2325

patch 8.1.2325: crash when using balloon with empty line Commit: https://github.com/vim/vim/commit/9ae862ebba4a8962cb1c6811a2a46656fa672599 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 21 13:27:06 2019 +0100 patch 8.1.2325: crash when using balloon with empty line Problem: Crash when using balloon with empty line. Solution: Handle empty lines. (Markus Braun)
author Bram Moolenaar <Bram@vim.org>
date Thu, 21 Nov 2019 13:30:03 +0100
parents 7369756d05de
children 592c7b56db69
comparison
equal deleted inserted replaced
18666:d451a92c772c 18667:de350001150c
1207 int copylen; 1207 int copylen;
1208 int ind; 1208 int ind;
1209 int cells; 1209 int cells;
1210 1210
1211 item = ((balpart_T *)ga.ga_data) + item_idx; 1211 item = ((balpart_T *)ga.ga_data) + item_idx;
1212 for (skip = 0; skip < item->bytelen; skip += thislen) 1212 if (item->bytelen == 0)
1213 { 1213 (*array)[line++].pum_text = vim_strsave((char_u *)"");
1214 if (split_long_items && item->cells >= BALLOON_MIN_WIDTH) 1214 else
1215 { 1215 for (skip = 0; skip < item->bytelen; skip += thislen)
1216 cells = item->indent * 2; 1216 {
1217 for (p = item->start + skip; p < item->start + item->bytelen; 1217 if (split_long_items && item->cells >= BALLOON_MIN_WIDTH)
1218 {
1219 cells = item->indent * 2;
1220 for (p = item->start + skip;
1221 p < item->start + item->bytelen;
1218 p += mb_ptr2len(p)) 1222 p += mb_ptr2len(p))
1219 if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH) 1223 if ((cells += ptr2cells(p)) > BALLOON_MIN_WIDTH)
1224 break;
1225 thislen = p - (item->start + skip);
1226 }
1227 else
1228 thislen = item->bytelen;
1229
1230 // put indent at the start
1231 p = alloc(thislen + item->indent * 2 + 1);
1232 if (p == NULL)
1233 {
1234 for (line = 0; line <= height - 1; ++line)
1235 vim_free((*array)[line].pum_text);
1236 vim_free(*array);
1237 goto failed;
1238 }
1239 for (ind = 0; ind < item->indent * 2; ++ind)
1240 p[ind] = ' ';
1241
1242 // exclude spaces at the end of the string
1243 for (copylen = thislen; copylen > 0; --copylen)
1244 if (item->start[skip + copylen - 1] != ' ')
1220 break; 1245 break;
1221 thislen = p - (item->start + skip); 1246
1222 } 1247 vim_strncpy(p + ind, item->start + skip, copylen);
1223 else 1248 (*array)[line].pum_text = p;
1224 thislen = item->bytelen; 1249 item->indent = 0; /* wrapped line has no indent */
1225 1250 ++line;
1226 // put indent at the start 1251 }
1227 p = alloc(thislen + item->indent * 2 + 1);
1228 if (p == NULL)
1229 {
1230 for (line = 0; line <= height - 1; ++line)
1231 vim_free((*array)[line].pum_text);
1232 vim_free(*array);
1233 goto failed;
1234 }
1235 for (ind = 0; ind < item->indent * 2; ++ind)
1236 p[ind] = ' ';
1237
1238 // exclude spaces at the end of the string
1239 for (copylen = thislen; copylen > 0; --copylen)
1240 if (item->start[skip + copylen - 1] != ' ')
1241 break;
1242
1243 vim_strncpy(p + ind, item->start + skip, copylen);
1244 (*array)[line].pum_text = p;
1245 item->indent = 0; /* wrapped line has no indent */
1246 ++line;
1247 }
1248 } 1252 }
1249 ga_clear(&ga); 1253 ga_clear(&ga);
1250 return height; 1254 return height;
1251 1255
1252 failed: 1256 failed: