1
0
forked from aniani/vim

patch 8.2.1560: using NULL pointers in some code

Problem:    Using NULL pointers in some code. (James McCoy)
Solution:   Avoid adding to a NULL pointer.  Use byte as unsigned.
This commit is contained in:
Bram Moolenaar
2020-09-01 19:56:15 +02:00
parent ca563b9b94
commit 9c2b06637b
6 changed files with 26 additions and 14 deletions

View File

@@ -395,7 +395,7 @@ skip_expr_concatenate(
typval_T rettv; typval_T rettv;
int res; int res;
int vim9script = in_vim9script(); int vim9script = in_vim9script();
garray_T *gap = &evalarg->eval_ga; garray_T *gap = evalarg == NULL ? NULL : &evalarg->eval_ga;
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags; int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
int evaluate = evalarg == NULL int evaluate = evalarg == NULL
? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE);

View File

@@ -1314,7 +1314,7 @@ setManualFoldWin(
if (!foldFind(gap, lnum, &fp)) if (!foldFind(gap, lnum, &fp))
{ {
// If there is a following fold, continue there next time. // If there is a following fold, continue there next time.
if (fp < (fold_T *)gap->ga_data + gap->ga_len) if (fp != NULL && fp < (fold_T *)gap->ga_data + gap->ga_len)
next = fp->fd_top + off; next = fp->fd_top + off;
break; break;
} }
@@ -2905,7 +2905,8 @@ foldSplit(
// any between top and bot, they have been removed by the caller. // any between top and bot, they have been removed by the caller.
gap1 = &fp->fd_nested; gap1 = &fp->fd_nested;
gap2 = &fp[1].fd_nested; gap2 = &fp[1].fd_nested;
(void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2)); if (foldFind(gap1, bot + 1 - fp->fd_top, &fp2))
{
len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2); len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
if (len > 0 && ga_grow(gap2, len) == OK) if (len > 0 && ga_grow(gap2, len) == OK)
{ {
@@ -2918,6 +2919,7 @@ foldSplit(
gap2->ga_len = len; gap2->ga_len = len;
gap1->ga_len -= len; gap1->ga_len -= len;
} }
}
fp->fd_len = top - fp->fd_top; fp->fd_len = top - fp->fd_top;
fold_changed = TRUE; fold_changed = TRUE;
} }

View File

@@ -816,7 +816,7 @@ read_cnt_string(FILE *fd, int cnt_bytes, int *cntp)
// read the length bytes, MSB first // read the length bytes, MSB first
for (i = 0; i < cnt_bytes; ++i) for (i = 0; i < cnt_bytes; ++i)
cnt = (cnt << 8) + getc(fd); cnt = (cnt << 8) + (unsigned)getc(fd);
if (cnt < 0) if (cnt < 0)
{ {
*cntp = SP_TRUNCERROR; *cntp = SP_TRUNCERROR;

View File

@@ -3606,6 +3606,8 @@ check_suggestions(
int len; int len;
hlf_T attr; hlf_T attr;
if (gap->ga_len == 0)
return;
stp = &SUG(*gap, 0); stp = &SUG(*gap, 0);
for (i = gap->ga_len - 1; i >= 0; --i) for (i = gap->ga_len - 1; i >= 0; --i)
{ {

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1560,
/**/ /**/
1559, 1559,
/**/ /**/

View File

@@ -1147,6 +1147,9 @@ generate_NEWLIST(cctx_T *cctx, int count)
isn->isn_arg.number = count; isn->isn_arg.number = count;
// get the member type from all the items on the stack. // get the member type from all the items on the stack.
if (count == 0)
member = &t_void;
else
member = get_member_type_from_stack( member = get_member_type_from_stack(
((type_T **)stack->ga_data) + stack->ga_len, count, 1, ((type_T **)stack->ga_data) + stack->ga_len, count, 1,
cctx->ctx_type_list); cctx->ctx_type_list);
@@ -1180,6 +1183,9 @@ generate_NEWDICT(cctx_T *cctx, int count)
return FAIL; return FAIL;
isn->isn_arg.number = count; isn->isn_arg.number = count;
if (count == 0)
member = &t_void;
else
member = get_member_type_from_stack( member = get_member_type_from_stack(
((type_T **)stack->ga_data) + stack->ga_len, count, 2, ((type_T **)stack->ga_data) + stack->ga_len, count, 2,
cctx->ctx_type_list); cctx->ctx_type_list);