Mercurial > vim
comparison src/quickfix.c @ 27897:2a2c0958a913 v8.2.4474
patch 8.2.4474: memory allocation failures not tested in quickfix code
Commit: https://github.com/vim/vim/commit/5a2d4a3ecb67942d47615507a163ffcd5863c073
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sat Feb 26 10:31:32 2022 +0000
patch 8.2.4474: memory allocation failures not tested in quickfix code
Problem: Memory allocation failures not tested in quickfix code.
Solution: Add alloc IDs and tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/9848)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 26 Feb 2022 11:45:03 +0100 |
parents | d1af65b322d0 |
children | b65a50d2fa4f |
comparison
equal
deleted
inserted
replaced
27896:960de0084729 | 27897:2a2c0958a913 |
---|---|
545 // Each part of the format string is copied and modified from errorformat | 545 // Each part of the format string is copied and modified from errorformat |
546 // to regex prog. Only a few % characters are allowed. | 546 // to regex prog. Only a few % characters are allowed. |
547 | 547 |
548 // Get some space to modify the format string into. | 548 // Get some space to modify the format string into. |
549 sz = efm_regpat_bufsz(efm); | 549 sz = efm_regpat_bufsz(efm); |
550 if ((fmtstr = alloc(sz)) == NULL) | 550 if ((fmtstr = alloc_id(sz, aid_qf_efm_fmtstr)) == NULL) |
551 goto parse_efm_error; | 551 goto parse_efm_error; |
552 | 552 |
553 while (efm[0] != NUL) | 553 while (efm[0] != NUL) |
554 { | 554 { |
555 // Allocate a new eformat structure and put it at the end of the list | 555 // Allocate a new eformat structure and put it at the end of the list |
556 fmt_ptr = ALLOC_CLEAR_ONE(efm_T); | 556 fmt_ptr = ALLOC_CLEAR_ONE_ID(efm_T, aid_qf_efm_fmtpart); |
557 if (fmt_ptr == NULL) | 557 if (fmt_ptr == NULL) |
558 goto parse_efm_error; | 558 goto parse_efm_error; |
559 if (fmt_first == NULL) // first one | 559 if (fmt_first == NULL) // first one |
560 fmt_first = fmt_ptr; | 560 fmt_first = fmt_ptr; |
561 else | 561 else |
626 // If the line exceeds LINE_MAXLEN exclude the last | 626 // If the line exceeds LINE_MAXLEN exclude the last |
627 // byte since it's not a NL character. | 627 // byte since it's not a NL character. |
628 state->linelen = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz; | 628 state->linelen = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz; |
629 if (state->growbuf == NULL) | 629 if (state->growbuf == NULL) |
630 { | 630 { |
631 state->growbuf = alloc(state->linelen + 1); | 631 state->growbuf = alloc_id(state->linelen + 1, aid_qf_linebuf); |
632 if (state->growbuf == NULL) | 632 if (state->growbuf == NULL) |
633 return NULL; | 633 return NULL; |
634 state->growbufsiz = state->linelen; | 634 state->growbufsiz = state->linelen; |
635 } | 635 } |
636 else if (state->linelen > state->growbufsiz) | 636 else if (state->linelen > state->growbufsiz) |
683 | 683 |
684 return QF_OK; | 684 return QF_OK; |
685 } | 685 } |
686 | 686 |
687 /* | 687 /* |
688 * Get the next string from state->p_Li. | 688 * Get the next string from the List item state->p_li. |
689 */ | 689 */ |
690 static int | 690 static int |
691 qf_get_next_list_line(qfstate_T *state) | 691 qf_get_next_list_line(qfstate_T *state) |
692 { | 692 { |
693 listitem_T *p_li = state->p_li; | 693 listitem_T *p_li = state->p_li; |
775 // The current line exceeds IObuff, continue reading using | 775 // The current line exceeds IObuff, continue reading using |
776 // growbuf until EOL or LINE_MAXLEN bytes is read. | 776 // growbuf until EOL or LINE_MAXLEN bytes is read. |
777 if (state->growbuf == NULL) | 777 if (state->growbuf == NULL) |
778 { | 778 { |
779 state->growbufsiz = 2 * (IOSIZE - 1); | 779 state->growbufsiz = 2 * (IOSIZE - 1); |
780 state->growbuf = alloc(state->growbufsiz); | 780 state->growbuf = alloc_id(state->growbufsiz, aid_qf_linebuf); |
781 if (state->growbuf == NULL) | 781 if (state->growbuf == NULL) |
782 return QF_NOMEM; | 782 return QF_NOMEM; |
783 } | 783 } |
784 | 784 |
785 // Copy the read part of the line, excluding null-terminator | 785 // Copy the read part of the line, excluding null-terminator |
1380 if (qfprev == NULL) | 1380 if (qfprev == NULL) |
1381 return QF_FAIL; | 1381 return QF_FAIL; |
1382 if (*fields->errmsg && !qfl->qf_multiignore) | 1382 if (*fields->errmsg && !qfl->qf_multiignore) |
1383 { | 1383 { |
1384 len = (int)STRLEN(qfprev->qf_text); | 1384 len = (int)STRLEN(qfprev->qf_text); |
1385 if ((ptr = alloc(len + STRLEN(fields->errmsg) + 2)) | 1385 ptr = alloc_id(len + STRLEN(fields->errmsg) + 2, |
1386 == NULL) | 1386 aid_qf_multiline_pfx); |
1387 if (ptr == NULL) | |
1387 return QF_FAIL; | 1388 return QF_FAIL; |
1388 STRCPY(ptr, qfprev->qf_text); | 1389 STRCPY(ptr, qfprev->qf_text); |
1389 vim_free(qfprev->qf_text); | 1390 vim_free(qfprev->qf_text); |
1390 qfprev->qf_text = ptr; | 1391 qfprev->qf_text = ptr; |
1391 *(ptr += len) = '\n'; | 1392 *(ptr += len) = '\n'; |
1857 { | 1858 { |
1858 VIM_CLEAR(qfl->qf_title); | 1859 VIM_CLEAR(qfl->qf_title); |
1859 | 1860 |
1860 if (title != NULL) | 1861 if (title != NULL) |
1861 { | 1862 { |
1862 char_u *p = alloc(STRLEN(title) + 2); | 1863 char_u *p = alloc_id(STRLEN(title) + 2, aid_qf_title); |
1863 | 1864 |
1864 qfl->qf_title = p; | 1865 qfl->qf_title = p; |
1865 if (p != NULL) | 1866 if (p != NULL) |
1866 STRCPY(p, title); | 1867 STRCPY(p, title); |
1867 } | 1868 } |
2107 int valid) // valid entry | 2108 int valid) // valid entry |
2108 { | 2109 { |
2109 qfline_T *qfp; | 2110 qfline_T *qfp; |
2110 qfline_T **lastp; // pointer to qf_last or NULL | 2111 qfline_T **lastp; // pointer to qf_last or NULL |
2111 | 2112 |
2112 if ((qfp = ALLOC_ONE(qfline_T)) == NULL) | 2113 if ((qfp = ALLOC_ONE_ID(qfline_T, aid_qf_qfline)) == NULL) |
2113 return QF_FAIL; | 2114 return QF_FAIL; |
2114 if (bufnum != 0) | 2115 if (bufnum != 0) |
2115 { | 2116 { |
2116 buf_T *buf = buflist_findnr(bufnum); | 2117 buf_T *buf = buflist_findnr(bufnum); |
2117 | 2118 |
2187 static qf_info_T * | 2188 static qf_info_T * |
2188 qf_alloc_stack(qfltype_T qfltype) | 2189 qf_alloc_stack(qfltype_T qfltype) |
2189 { | 2190 { |
2190 qf_info_T *qi; | 2191 qf_info_T *qi; |
2191 | 2192 |
2192 qi = ALLOC_CLEAR_ONE(qf_info_T); | 2193 qi = ALLOC_CLEAR_ONE_ID(qf_info_T, aid_qf_qfinfo); |
2193 if (qi != NULL) | 2194 if (qi != NULL) |
2194 { | 2195 { |
2195 qi->qf_refcount++; | 2196 qi->qf_refcount++; |
2196 qi->qfl_type = qfltype; | 2197 qi->qfl_type = qfltype; |
2197 qi->qf_bufnr = INVALID_QFBUFNR; | 2198 qi->qf_bufnr = INVALID_QFBUFNR; |
2481 { | 2482 { |
2482 struct dir_stack_T *ds_new; | 2483 struct dir_stack_T *ds_new; |
2483 struct dir_stack_T *ds_ptr; | 2484 struct dir_stack_T *ds_ptr; |
2484 | 2485 |
2485 // allocate new stack element and hook it in | 2486 // allocate new stack element and hook it in |
2486 ds_new = ALLOC_ONE(struct dir_stack_T); | 2487 ds_new = ALLOC_ONE_ID(struct dir_stack_T, aid_qf_dirstack); |
2487 if (ds_new == NULL) | 2488 if (ds_new == NULL) |
2488 return NULL; | 2489 return NULL; |
2489 | 2490 |
2490 ds_new->next = *stackptr; | 2491 ds_new->next = *stackptr; |
2491 *stackptr = ds_new; | 2492 *stackptr = ds_new; |
4943 if (start == -1) | 4944 if (start == -1) |
4944 start = mch_get_pid(); | 4945 start = mch_get_pid(); |
4945 else | 4946 else |
4946 off += 19; | 4947 off += 19; |
4947 | 4948 |
4948 name = alloc(STRLEN(p_mef) + 30); | 4949 name = alloc_id(STRLEN(p_mef) + 30, aid_qf_mef_name); |
4949 if (name == NULL) | 4950 if (name == NULL) |
4950 break; | 4951 break; |
4951 STRCPY(name, p_mef); | 4952 STRCPY(name, p_mef); |
4952 sprintf((char *)name + (p - p_mef), "%d%d", start, off); | 4953 sprintf((char *)name + (p - p_mef), "%d%d", start, off); |
4953 STRCAT(name, p + 2); | 4954 STRCAT(name, p + 2); |
4974 unsigned len; | 4975 unsigned len; |
4975 | 4976 |
4976 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(makecmd) + 1; | 4977 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(makecmd) + 1; |
4977 if (*p_sp != NUL) | 4978 if (*p_sp != NUL) |
4978 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; | 4979 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; |
4979 cmd = alloc(len); | 4980 cmd = alloc_id(len, aid_qf_makecmd); |
4980 if (cmd == NULL) | 4981 if (cmd == NULL) |
4981 return NULL; | 4982 return NULL; |
4982 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)makecmd, | 4983 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)makecmd, |
4983 (char *)p_shq); | 4984 (char *)p_shq); |
4984 | 4985 |
5040 return; | 5041 return; |
5041 mch_remove(fname); // in case it's not unique | 5042 mch_remove(fname); // in case it's not unique |
5042 | 5043 |
5043 cmd = make_get_fullcmd(eap->arg, fname); | 5044 cmd = make_get_fullcmd(eap->arg, fname); |
5044 if (cmd == NULL) | 5045 if (cmd == NULL) |
5046 { | |
5047 vim_free(fname); | |
5045 return; | 5048 return; |
5049 } | |
5046 | 5050 |
5047 // let the shell know if we are redirecting output or not | 5051 // let the shell know if we are redirecting output or not |
5048 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); | 5052 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); |
5049 | 5053 |
5050 #ifdef AMIGA | 5054 #ifdef AMIGA |