To: vim_dev@googlegroups.com Subject: Patch 8.2.0928 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0928 Problem: Many type casts are used for vim_strnsave(). Solution: Make the length argument size_t instead of int. (Ken Takata, closes #5633) Remove some type casts. Files: src/misc2.c, src/proto/misc2.pro, src/autocmd.c, src/channel.c, src/cmdexpand.c, src/dict.c, src/diff.c, src/digraph.c, src/eval.c, src/evalfunc.c, src/highlight.c, src/syntax.c *** ../vim-8.2.0927/src/misc2.c 2020-05-31 22:06:48.085779425 +0200 --- src/misc2.c 2020-06-07 20:38:50.580158021 +0200 *************** *** 1291,1297 **** * shorter. */ char_u * ! vim_strnsave(char_u *string, int len) { char_u *p; --- 1291,1297 ---- * shorter. */ char_u * ! vim_strnsave(char_u *string, size_t len) { char_u *p; *************** *** 1538,1544 **** * This uses ASCII lower-to-upper case translation, language independent. */ char_u * ! vim_strnsave_up(char_u *string, int len) { char_u *p1; --- 1538,1544 ---- * This uses ASCII lower-to-upper case translation, language independent. */ char_u * ! vim_strnsave_up(char_u *string, size_t len) { char_u *p1; *** ../vim-8.2.0927/src/proto/misc2.pro 2020-05-30 21:52:49.238816739 +0200 --- src/proto/misc2.pro 2020-06-07 20:40:12.719830176 +0200 *************** *** 32,45 **** void do_outofmem_msg(size_t size); void free_all_mem(void); char_u *vim_strsave(char_u *string); ! char_u *vim_strnsave(char_u *string, int len); char_u *vim_memsave(char_u *p, size_t len); char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars); char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl); int csh_like_shell(void); char_u *vim_strsave_shellescape(char_u *string, int do_special, int do_newline); char_u *vim_strsave_up(char_u *string); ! char_u *vim_strnsave_up(char_u *string, int len); void vim_strup(char_u *p); char_u *strup_save(char_u *orig); char_u *strlow_save(char_u *orig); --- 32,45 ---- void do_outofmem_msg(size_t size); void free_all_mem(void); char_u *vim_strsave(char_u *string); ! char_u *vim_strnsave(char_u *string, size_t len); char_u *vim_memsave(char_u *p, size_t len); char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars); char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl); int csh_like_shell(void); char_u *vim_strsave_shellescape(char_u *string, int do_special, int do_newline); char_u *vim_strsave_up(char_u *string); ! char_u *vim_strnsave_up(char_u *string, size_t len); void vim_strup(char_u *p); char_u *strup_save(char_u *orig); char_u *strlow_save(char_u *orig); *** ../vim-8.2.0927/src/autocmd.c 2020-04-02 18:50:42.415773144 +0200 --- src/autocmd.c 2020-06-07 20:41:04.287629232 +0200 *************** *** 763,769 **** save_ei = vim_strsave(p_ei); if (save_ei != NULL) { ! new_ei = vim_strnsave(p_ei, (int)(STRLEN(p_ei) + STRLEN(what))); if (new_ei != NULL) { if (*what == ',' && *p_ei == NUL) --- 763,769 ---- save_ei = vim_strsave(p_ei); if (save_ei != NULL) { ! new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what)); if (new_ei != NULL) { if (*what == ',' && *p_ei == NUL) *************** *** 991,997 **** ; if (p > arg) { ! group_name = vim_strnsave(arg, (int)(p - arg)); if (group_name == NULL) // out of memory return AUGROUP_ERROR; group = au_find_group(group_name); --- 991,997 ---- ; if (p > arg) { ! group_name = vim_strnsave(arg, p - arg); if (group_name == NULL) // out of memory return AUGROUP_ERROR; group = au_find_group(group_name); *** ../vim-8.2.0927/src/channel.c 2020-05-30 13:07:34.728769890 +0200 --- src/channel.c 2020-06-07 20:41:34.655512477 +0200 *************** *** 2906,2912 **** { // Copy the message into allocated memory (excluding the NL) // and remove it from the buffer (including the NL). ! msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } } --- 2906,2912 ---- { // Copy the message into allocated memory (excluding the NL) // and remove it from the buffer (including the NL). ! msg = vim_strnsave(buf, nl - buf); channel_consume(channel, part, (int)(nl - buf) + 1); } } *************** *** 3703,3709 **** { // Copy the message into allocated memory and remove it from the // buffer. ! msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } } --- 3703,3709 ---- { // Copy the message into allocated memory and remove it from the // buffer. ! msg = vim_strnsave(buf, nl - buf); channel_consume(channel, part, (int)(nl - buf) + 1); } } *** ../vim-8.2.0927/src/cmdexpand.c 2020-06-07 18:45:10.309351261 +0200 --- src/cmdexpand.c 2020-06-07 20:41:52.395444808 +0200 *************** *** 2555,2561 **** { if (ga_grow(&ga, 1) == FAIL) break; ! ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s)); ++ga.ga_len; } --- 2555,2561 ---- { if (ga_grow(&ga, 1) == FAIL) break; ! ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, e - s); ++ga.ga_len; } *** ../vim-8.2.0927/src/dict.c 2020-05-14 22:41:10.229637563 +0200 --- src/dict.c 2020-06-07 20:42:07.979385650 +0200 *************** *** 779,785 **** for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p) ; tv->v_type = VAR_STRING; ! tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg)); *arg = skipwhite(p); return OK; --- 779,785 ---- for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p) ; tv->v_type = VAR_STRING; ! tv->vval.v_string = vim_strnsave(*arg, p - *arg); *arg = skipwhite(p); return OK; *** ../vim-8.2.0927/src/diff.c 2020-05-30 20:30:42.888816585 +0200 --- src/diff.c 2020-06-07 20:42:24.991321381 +0200 *************** *** 1301,1307 **** if (curbuf->b_fname != NULL) { newname = vim_strnsave(curbuf->b_fname, ! (int)(STRLEN(curbuf->b_fname) + 4)); if (newname != NULL) STRCAT(newname, ".new"); } --- 1301,1307 ---- if (curbuf->b_fname != NULL) { newname = vim_strnsave(curbuf->b_fname, ! STRLEN(curbuf->b_fname) + 4); if (newname != NULL) STRCAT(newname, ".new"); } *** ../vim-8.2.0927/src/digraph.c 2019-12-01 20:52:55.000000000 +0100 --- src/digraph.c 2020-06-07 20:42:45.315244993 +0200 *************** *** 2387,2396 **** { kp = (kmap_T *)curbuf->b_kmap_ga.ga_data + curbuf->b_kmap_ga.ga_len; s = skiptowhite(p); ! kp->from = vim_strnsave(p, (int)(s - p)); p = skipwhite(s); s = skiptowhite(p); ! kp->to = vim_strnsave(p, (int)(s - p)); if (kp->from == NULL || kp->to == NULL || STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN --- 2387,2396 ---- { kp = (kmap_T *)curbuf->b_kmap_ga.ga_data + curbuf->b_kmap_ga.ga_len; s = skiptowhite(p); ! kp->from = vim_strnsave(p, s - p); p = skipwhite(s); s = skiptowhite(p); ! kp->to = vim_strnsave(p, s - p); if (kp->from == NULL || kp->to == NULL || STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN *** ../vim-8.2.0927/src/eval.c 2020-06-07 14:50:47.271846855 +0200 --- src/eval.c 2020-06-07 20:43:04.099174807 +0200 *************** *** 3139,3145 **** if (n1 >= len || n2 < 0 || n1 > n2) s = NULL; else ! s = vim_strnsave(s + n1, (int)(n2 - n1 + 1)); } else { --- 3139,3145 ---- if (n1 >= len || n2 < 0 || n1 > n2) s = NULL; else ! s = vim_strnsave(s + n1, n2 - n1 + 1); } else { *** ../vim-8.2.0927/src/evalfunc.c 2020-06-07 18:16:31.307293302 +0200 --- src/evalfunc.c 2020-06-07 20:43:43.299029435 +0200 *************** *** 5521,5527 **** vim_free(li1->li_tv.vval.v_string); li1->li_tv.vval.v_string = vim_strnsave(regmatch.startp[0], ! (int)(regmatch.endp[0] - regmatch.startp[0])); li3->li_tv.vval.v_number = (varnumber_T)(regmatch.startp[0] - expr); li4->li_tv.vval.v_number = --- 5521,5527 ---- vim_free(li1->li_tv.vval.v_string); li1->li_tv.vval.v_string = vim_strnsave(regmatch.startp[0], ! regmatch.endp[0] - regmatch.startp[0]); li3->li_tv.vval.v_number = (varnumber_T)(regmatch.startp[0] - expr); li4->li_tv.vval.v_number = *************** *** 5556,5562 **** copy_tv(&li->li_tv, rettv); else rettv->vval.v_string = vim_strnsave(regmatch.startp[0], ! (int)(regmatch.endp[0] - regmatch.startp[0])); } else if (l != NULL) rettv->vval.v_number = idx; --- 5556,5562 ---- copy_tv(&li->li_tv, rettv); else rettv->vval.v_string = vim_strnsave(regmatch.startp[0], ! regmatch.endp[0] - regmatch.startp[0]); } else if (l != NULL) rettv->vval.v_number = idx; *************** *** 8861,8867 **** } } } ! rettv->vval.v_string = vim_strnsave(head, (int)(tail - head)); } #ifdef FEAT_FLOAT --- 8861,8867 ---- } } } ! rettv->vval.v_string = vim_strnsave(head, tail - head); } #ifdef FEAT_FLOAT *** ../vim-8.2.0927/src/highlight.c 2020-06-05 19:36:53.468217572 +0200 --- src/highlight.c 2020-06-07 20:39:23.772024314 +0200 *************** *** 906,912 **** while (*linep && !VIM_ISWHITE(*linep) && *linep != '=') ++linep; vim_free(key); ! key = vim_strnsave_up(key_start, (int)(linep - key_start)); if (key == NULL) { error = TRUE; --- 906,912 ---- while (*linep && !VIM_ISWHITE(*linep) && *linep != '=') ++linep; vim_free(key); ! key = vim_strnsave_up(key_start, linep - key_start); if (key == NULL) { error = TRUE; *** ../vim-8.2.0927/src/syntax.c 2020-05-31 19:48:49.318871077 +0200 --- src/syntax.c 2020-06-07 20:39:53.815904736 +0200 *************** *** 5097,5103 **** while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') ++key_end; vim_free(key); ! key = vim_strnsave_up(rest, (int)(key_end - rest)); if (key == NULL) // out of memory { rest = NULL; --- 5097,5103 ---- while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') ++key_end; vim_free(key); ! key = vim_strnsave_up(rest, key_end - rest); if (key == NULL) // out of memory { rest = NULL; *************** *** 5762,5768 **** arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); vim_free(key); ! key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) --- 5762,5768 ---- arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); vim_free(key); ! key = vim_strnsave_up(arg_start, arg_end - arg_start); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) *** ../vim-8.2.0927/src/version.c 2020-06-07 20:07:40.137852214 +0200 --- src/version.c 2020-06-07 20:44:11.250926665 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 928, /**/ -- "My particular problem is with registry entries, which seem to just accumulate like plastic coffee cups..." -- Paul Moore /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///