Mercurial > vim
comparison src/libvterm/src/state.c @ 16429:a1229400434a v8.1.1219
patch 8.1.1219: not checking for NULL return from alloc()
commit https://github.com/vim/vim/commit/6ee9658774942f7448af700fc04df0335796a3db
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 27 22:06:37 2019 +0200
patch 8.1.1219: not checking for NULL return from alloc()
Problem: Not checking for NULL return from alloc().
Solution: Add checks. (Martin Kunev, closes https://github.com/vim/vim/issues/4303, closes https://github.com/vim/vim/issues/4174)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Apr 2019 22:15:05 +0200 |
parents | c1698187c482 |
children | d1357b505d78 |
comparison
equal
deleted
inserted
replaced
16428:6f69ef2913d7 | 16429:a1229400434a |
---|---|
251 VTermPos oldpos = state->pos; | 251 VTermPos oldpos = state->pos; |
252 | 252 |
253 // We'll have at most len codepoints, plus one from a previous incomplete | 253 // We'll have at most len codepoints, plus one from a previous incomplete |
254 // sequence. | 254 // sequence. |
255 codepoints = vterm_allocator_malloc(state->vt, (len + 1) * sizeof(uint32_t)); | 255 codepoints = vterm_allocator_malloc(state->vt, (len + 1) * sizeof(uint32_t)); |
256 if (codepoints == NULL) | |
257 return 0; | |
256 | 258 |
257 encoding = | 259 encoding = |
258 state->gsingle_set ? &state->encoding[state->gsingle_set] : | 260 state->gsingle_set ? &state->encoding[state->gsingle_set] : |
259 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : | 261 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : |
260 state->vt->mode.utf8 ? &state->encoding_utf8 : | 262 state->vt->mode.utf8 ? &state->encoding_utf8 : |
328 for(glyph_ends = i + 1; glyph_ends < npoints; glyph_ends++) | 330 for(glyph_ends = i + 1; glyph_ends < npoints; glyph_ends++) |
329 if(!vterm_unicode_is_combining(codepoints[glyph_ends])) | 331 if(!vterm_unicode_is_combining(codepoints[glyph_ends])) |
330 break; | 332 break; |
331 | 333 |
332 chars = vterm_allocator_malloc(state->vt, (glyph_ends - glyph_starts + 1) * sizeof(uint32_t)); | 334 chars = vterm_allocator_malloc(state->vt, (glyph_ends - glyph_starts + 1) * sizeof(uint32_t)); |
335 if (chars == NULL) | |
336 break; | |
333 | 337 |
334 for( ; i < glyph_ends; i++) { | 338 for( ; i < glyph_ends; i++) { |
335 int this_width; | 339 int this_width; |
336 chars[i - glyph_starts] = codepoints[i]; | 340 chars[i - glyph_starts] = codepoints[i]; |
337 this_width = vterm_unicode_width(codepoints[i]); | 341 this_width = vterm_unicode_width(codepoints[i]); |
1624 VTermPos oldpos = state->pos; | 1628 VTermPos oldpos = state->pos; |
1625 VTermPos delta = { 0, 0 }; | 1629 VTermPos delta = { 0, 0 }; |
1626 | 1630 |
1627 if(cols != state->cols) { | 1631 if(cols != state->cols) { |
1628 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); | 1632 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); |
1633 if (newtabstops == NULL) | |
1634 return 0; | |
1629 | 1635 |
1630 /* TODO: This can all be done much more efficiently bytewise */ | 1636 /* TODO: This can all be done much more efficiently bytewise */ |
1631 int col; | 1637 int col; |
1632 for(col = 0; col < state->cols && col < cols; col++) { | 1638 for(col = 0; col < state->cols && col < cols; col++) { |
1633 unsigned char mask = 1 << (col & 7); | 1639 unsigned char mask = 1 << (col & 7); |
1649 state->tabstops = newtabstops; | 1655 state->tabstops = newtabstops; |
1650 } | 1656 } |
1651 | 1657 |
1652 if(rows != state->rows) { | 1658 if(rows != state->rows) { |
1653 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); | 1659 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); |
1660 if (newlineinfo == NULL) | |
1661 return 0; | |
1654 | 1662 |
1655 int row; | 1663 int row; |
1656 for(row = 0; row < state->rows && row < rows; row++) { | 1664 for(row = 0; row < state->rows && row < rows; row++) { |
1657 newlineinfo[row] = state->lineinfo[row]; | 1665 newlineinfo[row] = state->lineinfo[row]; |
1658 } | 1666 } |