diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-05-24 18:54:09 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-05-24 18:54:09 +0200 |
commit | 964b3746b9c81e65887e2ac9a335f181db2bb592 (patch) | |
tree | 9afaaac41a1c4f71b359fd6706b88df00e22e7a1 | |
parent | d33a764123a8aedb20cd84aeff3b94810ee67c4c (diff) | |
download | vim-git-964b3746b9c81e65887e2ac9a335f181db2bb592.tar.gz |
patch 8.1.1384: using "int" for alloc() often results in compiler warningsv8.1.1384
Problem: Using "int" for alloc() often results in compiler warnings.
Solution: Use "size_t" and remove type casts. Remove alloc_check(), Vim
only works with 32 bit ints anyway.
63 files changed, 293 insertions, 322 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index e6cdb361e..614bc331f 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -1193,7 +1193,7 @@ do_autocmd_event( return FAIL; } - ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat)); + ap = (AutoPat *)alloc(sizeof(AutoPat)); if (ap == NULL) return FAIL; ap->pat = vim_strnsave(pat, patlen); @@ -1242,7 +1242,7 @@ do_autocmd_event( prev_ac = &(ap->cmds); while ((ac = *prev_ac) != NULL) prev_ac = &ac->next; - ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd)); + ac = (AutoCmd *)alloc(sizeof(AutoCmd)); if (ac == NULL) return FAIL; ac->cmd = vim_strsave(cmd); @@ -2303,8 +2303,8 @@ auto_next_pat( { name = event_nr2name(apc->event); s = _("%s Autocommands for \"%s\""); - sourcing_name = alloc((unsigned)(STRLEN(s) - + STRLEN(name) + ap->patlen + 1)); + sourcing_name = alloc(STRLEN(s) + + STRLEN(name) + ap->patlen + 1); if (sourcing_name != NULL) { sprintf((char *)sourcing_name, s, diff --git a/src/buffer.c b/src/buffer.c index 425c9143a..d99071674 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2577,7 +2577,7 @@ ExpandBufnames( /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ if (*pat == '^') { - patc = alloc((unsigned)STRLEN(pat) + 11); + patc = alloc(STRLEN(pat) + 11); if (patc == NULL) return FAIL; STRCPY(patc, "\\(^\\|[\\/]\\)"); @@ -2634,7 +2634,7 @@ ExpandBufnames( break; if (round == 1) { - *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); + *file = (char_u **)alloc(count * sizeof(char_u *)); if (*file == NULL) { vim_regfree(regmatch.regprog); diff --git a/src/change.c b/src/change.c index b43ba3574..d2aa1530f 100644 --- a/src/change.c +++ b/src/change.c @@ -985,7 +985,7 @@ ins_char_bytes(char_u *buf, int charlen) } } - newp = alloc_check((unsigned)(linelen + newlen - oldlen)); + newp = alloc(linelen + newlen - oldlen); if (newp == NULL) return; @@ -1060,7 +1060,7 @@ ins_str(char_u *s) oldp = ml_get(lnum); oldlen = (int)STRLEN(oldp); - newp = alloc_check((unsigned)(oldlen + newlen + 1)); + newp = alloc(oldlen + newlen + 1); if (newp == NULL) return; if (col > 0) @@ -1213,7 +1213,7 @@ del_bytes( newp = oldp; // use same allocated memory else { // need to allocate a new line - newp = alloc((unsigned)(newlen + 1)); + newp = alloc(newlen + 1); if (newp == NULL) return FAIL; mch_memmove(newp, oldp, (size_t)col); diff --git a/src/channel.c b/src/channel.c index 31c9bbe22..1564128ef 100644 --- a/src/channel.c +++ b/src/channel.c @@ -2024,7 +2024,7 @@ channel_parse_json(channel_T *channel, ch_part_T part) } else { - item = (jsonq_T *)alloc((unsigned)sizeof(jsonq_T)); + item = (jsonq_T *)alloc(sizeof(jsonq_T)); if (item == NULL) clear_tv(&listtv); else @@ -2223,7 +2223,7 @@ channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv) /* append after the last item that was pushed back */ item = item->jq_next; - newitem = (jsonq_T *)alloc((unsigned)sizeof(jsonq_T)); + newitem = (jsonq_T *)alloc(sizeof(jsonq_T)); if (newitem == NULL) clear_tv(rettv); else diff --git a/src/charset.c b/src/charset.c index cff62e185..171eccbfc 100644 --- a/src/charset.c +++ b/src/charset.c @@ -355,10 +355,10 @@ transstr(char_u *s) len += 4; /* illegal byte sequence */ } } - res = alloc((unsigned)(len + 1)); + res = alloc(len + 1); } else - res = alloc((unsigned)(vim_strsize(s) + 1)); + res = alloc(vim_strsize(s) + 1); if (res != NULL) { *res = NUL; diff --git a/src/debugger.c b/src/debugger.c index 78e32d33d..b79f61365 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -873,7 +873,7 @@ debuggy_find( // Replace K_SNR in function name with "<SNR>". if (!file && fname[0] == K_SPECIAL) { - name = alloc((unsigned)STRLEN(fname) + 3); + name = alloc(STRLEN(fname) + 3); if (name == NULL) name = fname; else diff --git a/src/dict.c b/src/dict.c index 007a7ff85..6e1d0d640 100644 --- a/src/dict.c +++ b/src/dict.c @@ -210,7 +210,7 @@ dictitem_alloc(char_u *key) { dictitem_T *di; - di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key))); + di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(key)); if (di != NULL) { STRCPY(di->di_key, key); @@ -228,8 +228,7 @@ dictitem_copy(dictitem_T *org) { dictitem_T *di; - di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) - + STRLEN(org->di_key))); + di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); if (di != NULL) { STRCPY(di->di_key, org->di_key); diff --git a/src/diff.c b/src/diff.c index 38ae0b47c..3c72e12bf 100644 --- a/src/diff.c +++ b/src/diff.c @@ -537,7 +537,7 @@ diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) { diff_T *dnew; - dnew = (diff_T *)alloc((unsigned)sizeof(diff_T)); + dnew = (diff_T *)alloc(sizeof(diff_T)); if (dnew != NULL) { dnew->df_next = dp; @@ -1123,7 +1123,7 @@ diff_file(diffio_T *dio) { len = STRLEN(tmp_orig) + STRLEN(tmp_new) + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; - cmd = alloc((unsigned)len); + cmd = alloc(len); if (cmd == NULL) return FAIL; @@ -1218,7 +1218,7 @@ ex_diffpatch(exarg_T *eap) if (esc_name == NULL) goto theend; buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16; - buf = alloc((unsigned)buflen); + buf = alloc(buflen); if (buf == NULL) goto theend; diff --git a/src/digraph.c b/src/digraph.c index d93613680..a26d10ca0 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -2317,7 +2317,7 @@ keymap_init(void) /* Source the keymap file. It will contain a ":loadkeymap" command * which will call ex_loadkeymap() below. */ buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; - buf = alloc((unsigned)buflen); + buf = alloc(buflen); if (buf == NULL) return e_outofmem; diff --git a/src/edit.c b/src/edit.c index 8a008cbfd..6e2fdb844 100644 --- a/src/edit.c +++ b/src/edit.c @@ -1943,7 +1943,7 @@ change_indent( { curwin->w_cursor.col = (colnr_T)new_cursor_col; i = (int)curwin->w_virtcol - vcol; - ptr = alloc((unsigned)(i + 1)); + ptr = alloc(i + 1); if (ptr != NULL) { new_cursor_col += i; diff --git a/src/eval.c b/src/eval.c index 695034899..4796a25bb 100644 --- a/src/eval.c +++ b/src/eval.c @@ -5151,7 +5151,7 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate) * Copy the string into allocated memory, handling backslashed * characters. */ - name = alloc((unsigned)(p - *arg + extra)); + name = alloc(p - *arg + extra); if (name == NULL) return FAIL; rettv->v_type = VAR_STRING; @@ -5285,7 +5285,7 @@ get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate) /* * Copy the string into allocated memory, handling '' to ' reduction. */ - str = alloc((unsigned)((p - *arg) - reduce)); + str = alloc((p - *arg) - reduce); if (str == NULL) return FAIL; rettv->v_type = VAR_STRING; @@ -6782,8 +6782,8 @@ make_expanded_name( temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE); if (temp_result != NULL && nextcmd == NULL) { - retval = alloc((unsigned)(STRLEN(temp_result) + (expr_start - in_start) - + (in_end - expr_end) + 1)); + retval = alloc(STRLEN(temp_result) + (expr_start - in_start) + + (in_end - expr_end) + 1); if (retval != NULL) { STRCPY(retval, in_start); @@ -8130,8 +8130,7 @@ set_var( if (!valid_varname(varname)) return; - v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) - + STRLEN(varname))); + v = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(varname)); if (v == NULL) return; STRCPY(v->di_key, varname); @@ -8993,7 +8992,7 @@ setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off) } else { - winvarname = alloc((unsigned)STRLEN(varname) + 3); + winvarname = alloc(STRLEN(varname) + 3); if (winvarname != NULL) { STRCPY(winvarname, "w:"); @@ -9056,7 +9055,7 @@ autoload_name(char_u *name) char_u *scriptname; /* Get the script file name: replace '#' with '/', append ".vim". */ - scriptname = alloc((unsigned)(STRLEN(name) + 14)); + scriptname = alloc(STRLEN(name) + 14); if (scriptname == NULL) return FALSE; STRCPY(scriptname, "autoload/"); diff --git a/src/evalfunc.c b/src/evalfunc.c index 6ffd1a1ab..58ea7103f 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4272,10 +4272,10 @@ f_foldtext(typval_T *argvars UNUSED, typval_T *rettv) } count = (long)(foldend - foldstart + 1); txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count); - r = alloc((unsigned)(STRLEN(txt) - + STRLEN(dashes) /* for %s */ - + 20 /* for %3ld */ - + STRLEN(s))); /* concatenated */ + r = alloc(STRLEN(txt) + + STRLEN(dashes) // for %s + + 20 // for %3ld + + STRLEN(s)); // concatenated if (r != NULL) { sprintf((char *)r, txt, dashes, count); @@ -10386,7 +10386,7 @@ f_resolve(typval_T *argvars, typval_T *rettv) if (q > p && !mch_isFullName(buf)) { /* symlink is relative to directory of argument */ - cpy = alloc((unsigned)(STRLEN(p) + STRLEN(buf) + 1)); + cpy = alloc(STRLEN(p) + STRLEN(buf) + 1); if (cpy != NULL) { STRCPY(cpy, p); @@ -11067,8 +11067,8 @@ do_searchpair( /* Make two search patterns: start/end (pat2, for in nested pairs) and * start/middle/end (pat3, for the top pair). */ - pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 17)); - pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25)); + pat2 = alloc(STRLEN(spat) + STRLEN(epat) + 17); + pat3 = alloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25); if (pat2 == NULL || pat3 == NULL) goto theend; sprintf((char *)pat2, "\\m\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); @@ -11328,7 +11328,7 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED) { buf_T *save_curbuf = curbuf; - bufvarname = alloc((unsigned)STRLEN(varname) + 3); + bufvarname = alloc(STRLEN(varname) + 3); if (bufvarname != NULL) { curbuf = buf; @@ -11850,7 +11850,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv) save_curtab = curtab; goto_tabpage_tp(tp, FALSE, FALSE); - tabvarname = alloc((unsigned)STRLEN(varname) + 3); + tabvarname = alloc(STRLEN(varname) + 3); if (tabvarname != NULL) { STRCPY(tabvarname, "t:"); @@ -13921,7 +13921,7 @@ get_cmd_output_as_rettv( ++i; end = res + i; - s = alloc((unsigned)(end - start + 1)); + s = alloc(end - start + 1); if (s == NULL) goto errret; diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 040514cdc..7420d6752 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -595,10 +595,10 @@ ex_sort(exarg_T *eap) } /* Allocate a buffer that can hold the longest line. */ - sortbuf1 = alloc((unsigned)maxlen + 1); + sortbuf1 = alloc(maxlen + 1); if (sortbuf1 == NULL) goto sortend; - sortbuf2 = alloc((unsigned)maxlen + 1); + sortbuf2 = alloc(maxlen + 1); if (sortbuf2 == NULL) goto sortend; @@ -1146,7 +1146,7 @@ do_bang( } len += (int)STRLEN(prevcmd); } - if ((t = alloc((unsigned)len)) == NULL) + if ((t = alloc(len)) == NULL) { vim_free(newcmd); return; @@ -1209,7 +1209,7 @@ do_bang( */ if (*p_shq != NUL) { - newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); + newcmd = alloc(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1); if (newcmd == NULL) return; STRCPY(newcmd, p_shq); @@ -3908,7 +3908,7 @@ do_ecmd( len = (int)STRLEN(command) + 3; else len = 30; - p = alloc((unsigned)len); + p = alloc(len); if (p != NULL) { if (command != NULL) @@ -5634,7 +5634,7 @@ do_sub(exarg_T *eap) * too many calls to alloc()/free()). */ new_start_len = needed_len + 50; - if ((new_start = alloc_check(new_start_len)) == NULL) + if ((new_start = alloc(new_start_len)) == NULL) goto outofmem; *new_start = NUL; new_end = new_start; @@ -5651,7 +5651,7 @@ do_sub(exarg_T *eap) if (needed_len > (int)new_start_len) { new_start_len = needed_len + 50; - if ((p1 = alloc_check(new_start_len)) == NULL) + if ((p1 = alloc(new_start_len)) == NULL) { vim_free(new_start); goto outofmem; @@ -7320,7 +7320,7 @@ helptags_one( got_int = TRUE; break; } - s = alloc((unsigned)(p2 - p1 + STRLEN(fname) + 2)); + s = alloc(p2 - p1 + STRLEN(fname) + 2); if (s == NULL) { got_int = TRUE; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 59452032b..c56e30533 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -2366,7 +2366,7 @@ ex_compiler(exarg_T *eap) } else { - buf = alloc((unsigned)(STRLEN(eap->arg) + 14)); + buf = alloc(STRLEN(eap->arg) + 14); if (buf != NULL) { if (eap->forceit) diff --git a/src/ex_docmd.c b/src/ex_docmd.c index f4f7639e7..c6e00bec5 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -5094,7 +5094,7 @@ repl_cmdline( i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3; if (eap->nextcmd != NULL) i += (int)STRLEN(eap->nextcmd);/* add space for next command */ - if ((new_cmdline = alloc((unsigned)i)) == NULL) + if ((new_cmdline = alloc(i)) == NULL) return NULL; /* out of memory! */ /* @@ -6547,7 +6547,7 @@ alist_unlink(alist_T *al) void alist_new(void) { - curwin->w_alist = (alist_T *)alloc((unsigned)sizeof(alist_T)); + curwin->w_alist = (alist_T *)alloc(sizeof(alist_T)); if (curwin->w_alist == NULL) { curwin->w_alist = &global_alist; @@ -6581,7 +6581,7 @@ alist_expand(int *fnum_list, int fnum_len) * expansion. Also, the vimrc file isn't read yet, thus the user * can't set the options. */ p_su = empty_option; - old_arg_files = (char_u **)alloc((unsigned)(sizeof(char_u *) * GARGCOUNT)); + old_arg_files = (char_u **)alloc(sizeof(char_u *) * GARGCOUNT); if (old_arg_files != NULL) { for (i = 0; i < GARGCOUNT; ++i) @@ -8839,7 +8839,7 @@ ex_normal(exarg_T *eap) } if (len > 0) { - arg = alloc((unsigned)(STRLEN(eap->arg) + len + 1)); + arg = alloc(STRLEN(eap->arg) + len + 1); if (arg != NULL) { len = 0; @@ -9628,7 +9628,7 @@ arg_all(void) } /* allocate memory */ - retval = alloc((unsigned)len + 1); + retval = alloc(len + 1); if (retval == NULL) break; } @@ -10622,7 +10622,7 @@ get_view_file(int c) for (p = sname; *p; ++p) if (*p == '=' || vim_ispathsep(*p)) ++len; - retval = alloc((unsigned)(STRLEN(sname) + len + STRLEN(p_vdir) + 9)); + retval = alloc(STRLEN(sname) + len + STRLEN(p_vdir) + 9); if (retval != NULL) { STRCPY(retval, p_vdir); diff --git a/src/ex_eval.c b/src/ex_eval.c index 63bca6718..b1bb7e5dd 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -251,7 +251,7 @@ cause_errthrow( while (*plist != NULL) plist = &(*plist)->next; - elem = (struct msglist *)alloc((unsigned)sizeof(struct msglist)); + elem = (struct msglist *)alloc(sizeof(struct msglist)); if (elem == NULL) { suppress_errthrow = TRUE; @@ -519,7 +519,7 @@ throw_exception(void *value, except_type_T type, char_u *cmdname) } } - excp = (except_T *)alloc((unsigned)sizeof(except_T)); + excp = (except_T *)alloc(sizeof(except_T)); if (excp == NULL) goto nomem; @@ -1441,7 +1441,7 @@ ex_try(exarg_T *eap) { eslist_T *elem; - elem = (eslist_T *)alloc((unsigned)sizeof(struct eslist_elem)); + elem = (eslist_T *)alloc(sizeof(struct eslist_elem)); if (elem == NULL) emsg(_(e_outofmem)); else diff --git a/src/ex_getln.c b/src/ex_getln.c index ba3dc7358..00193fee8 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -4154,7 +4154,7 @@ ExpandOne( } } - ss = alloc((unsigned)len + 1); + ss = alloc(len + 1); if (ss) vim_strncpy(ss, xp->xp_files[0], (size_t)len); findex = -1; /* next p_wc gets first one */ @@ -4362,7 +4362,7 @@ escape_fname(char_u **pp) { char_u *p; - p = alloc((unsigned)(STRLEN(*pp) + 2)); + p = alloc(STRLEN(*pp) + 2); if (p != NULL) { p[0] = '\\'; @@ -5294,7 +5294,7 @@ ExpandGeneric( if (count == 0) return OK; *num_file = count; - *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); + *file = (char_u **)alloc(count * sizeof(char_u *)); if (*file == NULL) { *file = (char_u **)""; @@ -5636,7 +5636,7 @@ ExpandRTDir( for (i = 0; dirnames[i] != NULL; ++i) { - s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); + s = alloc(STRLEN(dirnames[i]) + pat_len + 7); if (s == NULL) { ga_clear_strings(&ga); @@ -5650,7 +5650,7 @@ ExpandRTDir( if (flags & DIP_START) { for (i = 0; dirnames[i] != NULL; ++i) { - s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 22)); + s = alloc(STRLEN(dirnames[i]) + pat_len + 22); if (s == NULL) { ga_clear_strings(&ga); @@ -5665,7 +5665,7 @@ ExpandRTDir( if (flags & DIP_OPT) { for (i = 0; dirnames[i] != NULL; ++i) { - s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 20)); + s = alloc(STRLEN(dirnames[i]) + pat_len + 20); if (s == NULL) { ga_clear_strings(&ga); @@ -5728,7 +5728,7 @@ ExpandPackAddDir( pat_len = (int)STRLEN(pat); ga_init2(&ga, (int)sizeof(char *), 10); - s = alloc((unsigned)(pat_len + 26)); + s = alloc(pat_len + 26); if (s == NULL) { ga_clear_strings(&ga); diff --git a/src/fileio.c b/src/fileio.c index 57c5f47fc..e41f96762 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -6203,7 +6203,7 @@ buf_modname( */ if (fname == NULL || *fname == NUL) { - retval = alloc((unsigned)(MAXPATHL + extlen + 3)); + retval = alloc(MAXPATHL + extlen + 3); if (retval == NULL) return NULL; if (mch_dirname(retval, MAXPATHL) == FAIL || @@ -6222,7 +6222,7 @@ buf_modname( else { fnamelen = (int)STRLEN(fname); - retval = alloc((unsigned)(fnamelen + extlen + 3)); + retval = alloc(fnamelen + extlen + 3); if (retval == NULL) return NULL; STRCPY(retval, fname); @@ -6894,8 +6894,8 @@ buf_check_timestamp( { if (!helpmesg) mesg2 = ""; - tbuf = (char *)alloc((unsigned)(STRLEN(path) + STRLEN(mesg) - + STRLEN(mesg2) + 2)); + tbuf = (char *)alloc(STRLEN(path) + STRLEN(mesg) + + STRLEN(mesg2) + 2); sprintf(tbuf, mesg, path); #ifdef FEAT_EVAL /* Set warningmsg here, before the unimportant and output-specific @@ -7391,7 +7391,7 @@ vim_settempdir(char_u *tempdir) { char_u *buf; - buf = alloc((unsigned)MAXPATHL + 2); + buf = alloc(MAXPATHL + 2); if (buf != NULL) { if (vim_FullName(tempdir, buf, MAXPATHL, FALSE) == FAIL) diff --git a/src/findfile.c b/src/findfile.c index 3d3aec0df..a6d164ad2 100644 --- a/src/findfile.c +++ b/src/findfile.c @@ -319,7 +319,7 @@ vim_findfile_init( search_ctx = search_ctx_arg; else { - search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T)); + search_ctx = (ff_search_ctx_T*)alloc(sizeof(ff_search_ctx_T)); if (search_ctx == NULL) goto error_return; vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T)); @@ -430,8 +430,7 @@ vim_findfile_init( walker++; dircount = 1; - search_ctx->ffsc_stopdirs_v = - (char_u **)alloc((unsigned)sizeof(char_u *)); + search_ctx->ffsc_stopdirs_v = (char_u **)alloc(sizeof(char_u *)); if (search_ctx->ffsc_stopdirs_v != NULL) { @@ -926,8 +925,7 @@ vim_findfile(void *search_ctx_arg) */ if (path_with_url(dirptrs[0])) { - stackp->ffs_filearray = (char_u **) - alloc((unsigned)sizeof(char *)); + stackp->ffs_filearray = (char_u **)alloc(sizeof(char *)); if (stackp->ffs_filearray != NULL && (stackp->ffs_filearray[0] = vim_strsave(dirptrs[0])) != NULL) @@ -1285,7 +1283,7 @@ ff_get_visited_list( /* * if we reach this we didn't find a list and we have to allocate new list */ - retptr = (ff_visited_list_hdr_T*)alloc((unsigned)sizeof(*retptr)); + retptr = (ff_visited_list_hdr_T*)alloc(sizeof(*retptr)); if (retptr == NULL) return NULL; @@ -1413,8 +1411,7 @@ ff_check_visited( /* * New file/dir. Add it to the list of visited files/dirs. */ - vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T) - + STRLEN(ff_expand_buffer))); + vp = (ff_visited_T *)alloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); if (vp != NULL) { @@ -1462,7 +1459,7 @@ ff_create_stack_element( { ff_stack_T *new; - new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T)); + new = (ff_stack_T *)alloc(sizeof(ff_stack_T)); if (new == NULL) return NULL; @@ -2579,7 +2576,7 @@ expand_in_path( char_u *paths = NULL; int glob_flags = 0; - if ((curdir = alloc((unsigned)MAXPATHL)) == NULL) + if ((curdir = alloc(MAXPATHL)) == NULL) return 0; mch_dirname(curdir, MAXPATHL); diff --git a/src/fold.c b/src/fold.c index 7446f7c63..4cc7a477d 100644 --- a/src/fold.c +++ b/src/fold.c @@ -1770,7 +1770,7 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen) /* Check if the line ends with an unclosed comment */ (void)skip_comment(line, FALSE, FALSE, &line_is_comment); #endif - newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1)); + newline = alloc(line_len + markerlen + STRLEN(cms) + 1); if (newline == NULL) return; STRCPY(newline, line); @@ -1849,7 +1849,7 @@ foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) if (u_save(lnum - 1, lnum + 1) == OK) { /* Make new line: text-before-marker + text-after-marker */ - newline = alloc((unsigned)(STRLEN(line) - len + 1)); + newline = alloc(STRLEN(line) - len + 1); if (newline != NULL) { STRNCPY(newline, line, p - line); diff --git a/src/getchar.c b/src/getchar.c index debad7efd..0ebe715cd 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -3731,7 +3731,7 @@ do_map( /* * Get here when adding a new entry to the maphash[] list or abbrlist. */ - mp = (mapblock_T *)alloc((unsigned)sizeof(mapblock_T)); + mp = (mapblock_T *)alloc(sizeof(mapblock_T)); if (mp == NULL) { retval = 4; /* no mem */ @@ -4375,7 +4375,7 @@ ExpandMappings( if (round == 1) { - *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); + *file = (char_u **)alloc(count * sizeof(char_u *)); if (*file == NULL) return FAIL; } @@ -4695,7 +4695,7 @@ vim_strsave_escape_csi( /* Need a buffer to hold up to three times as much. Four in case of an * illegal utf-8 byte: * 0xc0 -> 0xc3 0x80 -> 0xc3 K_SPECIAL KS_SPECIAL KE_FILLER */ - res = alloc((unsigned)(STRLEN(p) * 4) + 1); + res = alloc(STRLEN(p) * 4 + 1); if (res != NULL) { d = res; @@ -2162,7 +2162,7 @@ gui_screenstr( if (enc_utf8) { - buf = alloc((unsigned)(len * MB_MAXBYTES + 1)); + buf = alloc(len * MB_MAXBYTES + 1); if (buf == NULL) return OK; /* not much we could do here... */ @@ -2185,7 +2185,7 @@ gui_screenstr( } else if (enc_dbcs == DBCS_JPNU) { - buf = alloc((unsigned)(len * 2 + 1)); + buf = alloc(len * 2 + 1); if (buf == NULL) return OK; /* not much we could do here... */ diff --git a/src/gui_at_fs.c b/src/gui_at_fs.c index e65a26648..c50816b82 100644 --- a/src/gui_at_fs.c +++ b/src/gui_at_fs.c @@ -499,7 +499,7 @@ SFgetHomeDirs(void) (unsigned)(Alloc * sizeof(SFLogin))); } len = strlen(pw->pw_name); - entries[i].real = XtMalloc((unsigned) (len + 3)); + entries[i].real = XtMalloc((unsigned)(len + 3)); (void) strcat(strcpy(entries[i].real, "~"), pw->pw_name); entries[i].shown = entries[i].real; entries[i].statDone = 1; @@ -1307,7 +1307,7 @@ SFstatAndCheck(SFDir *dir, SFEntry *entry) int len; len = strlen(shown); - entry->shown = XtMalloc((unsigned) (len + 2)); + entry->shown = XtMalloc((unsigned)(len + 2)); (void) strcpy(entry->shown, shown); SFwriteStatChar(entry->shown, len, &statBuf); entry->shown[len + 1] = 0; @@ -2032,7 +2032,7 @@ SFgetDir( result[i].statDone = 0; str = dp->d_name; len = strlen(str); - result[i].real = XtMalloc((unsigned) (len + 2)); + result[i].real = XtMalloc((unsigned)(len + 2)); (void) strcat(strcpy(result[i].real, str), " "); if (len > maxChars) maxChars = len; diff --git a/src/gui_gtk.c b/src/gui_gtk.c index 126eaf06d..853706027 100644 --- a/src/gui_gtk.c +++ b/src/gui_gtk.c @@ -559,7 +559,7 @@ translate_mnemonic_tag(char_u *name, int use_mnemonic) if (*psrc == '_') ++n_underscores; - buf = alloc((unsigned)(psrc - name + n_underscores + 1)); + buf = alloc(psrc - name + n_underscores + 1); if (buf != NULL) { pdest = buf; diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index 7d1d8d0c5..17ef6eabd 100644 --- a/src/gui_gtk_x11.c +++ b/src/gui_gtk_x11.c @@ -429,7 +429,7 @@ gui_mch_prepare(int *argc, char **argv) * into gui_argv. Freed later in gui_mch_init(). */ gui_argc = 0; - gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); + gui_argv = (char **)alloc((*argc + 1) * sizeof(char *)); g_return_if_fail(gui_argv != NULL); @@ -1544,7 +1544,7 @@ selection_get_cb(GtkWidget *widget UNUSED, if (info == (guint)TARGET_VIM) { - tmpbuf = alloc((unsigned)length + 1); + tmpbuf = alloc(length + 1); if (tmpbuf != NULL) { tmpbuf[0] = motion_type; @@ -1603,7 +1603,7 @@ selection_get_cb(GtkWidget *widget UNUSED, int l = STRLEN(p_enc); /* contents: motion_type 'encoding' NUL text */ - tmpbuf = alloc((unsigned)length + l + 2); + tmpbuf = alloc(length + l + 2); if (tmpbuf != NULL) { tmpbuf[0] = motion_type; @@ -2512,8 +2512,7 @@ setup_save_yourself(void) if (i == count) { /* allocate an Atoms array which is one item longer */ - new_atoms = (Atom *)alloc((unsigned)((count + 1) - * sizeof(Atom))); + new_atoms = (Atom *)alloc((count + 1) * sizeof(Atom)); if (new_atoms != NULL) { memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); diff --git a/src/gui_motif.c b/src/gui_motif.c index 421733933..1693df974 100644 --- a/src/gui_motif.c +++ b/src/gui_motif.c @@ -2538,7 +2538,7 @@ gui_mch_dialog( for (p = buts; *p; ++p) if (*p == DLG_BUTTON_SEP) ++butcount; - buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget))); + buttons = (Widget *)alloc(butcount * sizeof(Widget)); if (buttons == NULL) { vim_free(buts); diff --git a/src/gui_w32.c b/src/gui_w32.c index 596183073..bf2738606 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -3120,9 +3120,9 @@ logfont2name(LOGFONTW lf) charset_name = charset_id2name((int)lf.lfCharSet); quality_name = quality_id2name((int)lf.lfQuality); - res = (char *)alloc((unsigned)(strlen(font_name) + 30 + res = (char *)alloc(strlen(font_name) + 30 + (charset_name == NULL ? 0 : strlen(charset_name) + 2) - + (quality_name == NULL ? 0 : strlen(quality_name) + 2))); + + (quality_name == NULL ? 0 : strlen(quality_name) + 2)); if (res != NULL) { p = res; @@ -7718,7 +7718,7 @@ gui_mch_tearoff( } /* Allocate menu label and fill it in */ - text = label = alloc((unsigned)len + 1); + text = label = alloc(len + 1); if (label == NULL) break; diff --git a/src/hashtab.c b/src/hashtab.c index 6f2c2ca7b..54f7500c2 100644 --- a/src/hashtab.c +++ b/src/hashtab.c @@ -400,8 +400,7 @@ hash_may_resize( else { /* Allocate an array. */ - newarray = (hashitem_T *)alloc((unsigned) - (sizeof(hashitem_T) * newsize)); + newarray = (hashitem_T *)alloc(sizeof(hashitem_T) * newsize); if (newarray == NULL) { /* Out of memory. When there are NULL items still return OK. diff --git a/src/if_cscope.c b/src/if_cscope.c index 93a0458b4..4d5748910 100644 --- a/src/if_cscope.c +++ b/src/if_cscope.c @@ -466,7 +466,7 @@ cs_add(exarg_T *eap UNUSED) cs_stat_emsg(char *fname) { char *stat_emsg = _("E563: stat(%s) error: %d"); - char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10); + char *buf = (char *)alloc(strlen(stat_emsg) + MAXPATHL + 10); if (buf != NULL) { @@ -543,7 +543,7 @@ staterr: /* if filename is a directory, append the cscope database name to it */ if (S_ISDIR(statbuf.st_mode)) { - fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2)); + fname2 = (char *)alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); if (fname2 == NULL) goto add_err; @@ -769,7 +769,7 @@ cs_create_cmd(char *csoption, char *pattern) while VIM_ISWHITE(*pat) ++pat; - if ((cmd = (char *)alloc((unsigned)(strlen(pat) + 2))) == NULL) + if ((cmd = (char *)alloc(strlen(pat) + 2)) == NULL) return NULL; (void)sprintf(cmd, "%d%s", search, pat); @@ -1121,7 +1121,7 @@ cs_find_common( if (strchr(CSQF_FLAGS, *qfpos) == NULL) { char *nf = _("E469: invalid cscopequickfix flag %c for %c"); - char *buf = (char *)alloc((unsigned)strlen(nf)); + char *buf = (char *)alloc(strlen(nf)); /* strlen will be enough because we use chars */ if (buf != NULL) @@ -1192,7 +1192,7 @@ cs_find_common( return FALSE; } - buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); + buf = (char *)alloc(strlen(opt) + strlen(pat) + strlen(nf)); if (buf == NULL) (void)emsg(nf); else @@ -1450,14 +1450,14 @@ cs_insert_filelist( clear_csinfo(j); } - if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL) + if ((csinfo[i].fname = (char *)alloc(strlen(fname)+1)) == NULL) return -1; (void)strcpy(csinfo[i].fname, (const char *)fname); if (ppath != NULL) { - if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL) + if ((csinfo[i].ppath = (char *)alloc(strlen(ppath) + 1)) == NULL) { VIM_CLEAR(csinfo[i].fname); return -1; @@ -1468,7 +1468,7 @@ cs_insert_filelist( if (flags != NULL) { - if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL) + if ((csinfo[i].flags = (char *)alloc(strlen(flags) + 1)) == NULL) { VIM_CLEAR(csinfo[i].fname); VIM_CLEAR(csinfo[i].ppath); @@ -1820,7 +1820,7 @@ cs_file_results(FILE *f, int *nummatches_a) &slno, &search)) == NULL) continue; - context = (char *)alloc((unsigned)strlen(cntx)+5); + context = (char *)alloc(strlen(cntx)+5); if (context == NULL) continue; @@ -1975,7 +1975,7 @@ cs_print_tags_priv(char **matches, char **cntxts, int num_matches) assert(num_matches > 0); - if ((tbuf = (char *)alloc((unsigned)strlen(matches[0]) + 1)) == NULL) + if ((tbuf = (char *)alloc(strlen(matches[0]) + 1)) == NULL) return; strcpy(tbuf, matches[0]); @@ -2010,7 +2010,7 @@ cs_print_tags_priv(char **matches, char **cntxts, int num_matches) * by parsing matches[i] on the fly and placing stuff into buf * directly, but that's too much of a hassle */ - if ((tbuf = (char *)alloc((unsigned)strlen(matches[idx]) + 1)) == NULL) + if ((tbuf = (char *)alloc(strlen(matches[idx]) + 1)) == NULL) continue; (void)strcpy(tbuf, matches[idx]); diff --git a/src/if_perlsfio.c b/src/if_perlsfio.c index 528a1b4f1..31f0c6b3e 100644 --- a/src/if_perlsfio.c +++ b/src/if_perlsfio.c @@ -51,7 +51,7 @@ sfdcnewvim(void) { Sfdisc_t *disc; - disc = (Sfdisc_t *)alloc((unsigned)sizeof(Sfdisc_t)); + disc = (Sfdisc_t *)alloc(sizeof(Sfdisc_t)); if (disc == NULL) return NULL; diff --git a/src/if_python3.c b/src/if_python3.c index d93d63318..823cfea3b 100644 --- a/src/if_python3.c +++ b/src/if_python3.c @@ -1629,7 +1629,7 @@ LineToString(const char *str) Py_ssize_t len = strlen(str); char *tmp,*p; - tmp = (char *)alloc((unsigned)(len+1)); + tmp = (char *)alloc(len + 1); p = tmp; if (p == NULL) { diff --git a/src/if_xcmdsrv.c b/src/if_xcmdsrv.c index 430548eb3..4b44126d5 100644 --- a/src/if_xcmdsrv.c +++ b/src/if_xcmdsrv.c @@ -441,7 +441,7 @@ serverSendToVim( * Length must be computed exactly! */ length = STRLEN(name) + STRLEN(p_enc) + STRLEN(cmd) + 14; - property = (char_u *)alloc((unsigned)length + 30); + property = (char_u *)alloc(length + 30); sprintf((char *)property, "%c%c%c-n %s%c-E %s%c-s %s", 0, asExpr ? 'c' : 'k', 0, name, 0, p_enc, 0, cmd); @@ -750,7 +750,7 @@ serverSendReply(char_u *name, char_u *str) return -1; length = STRLEN(p_enc) + STRLEN(str) + 14; - if ((property = (char_u *)alloc((unsigned)length + 30)) != NULL) + if ((property = (char_u *)alloc(length + 30)) != NULL) { sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); diff --git a/src/indent.c b/src/indent.c index 893ca298c..8499b8134 100644 --- a/src/indent.c +++ b/src/indent.c @@ -28,7 +28,7 @@ cin_is_cinword(char_u *line) int len; cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1; - cinw_buf = alloc((unsigned)cinw_len); + cinw_buf = alloc(cinw_len); if (cinw_buf != NULL) { line = skipwhite(line); diff --git a/src/insexpand.c b/src/insexpand.c index eeff64ca2..4a807f48c 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -473,7 +473,7 @@ ins_compl_add_infercase( ? actual_len : actual_compl_length; // Allocate wide character array for the completion and fill it. - wca = (int *)alloc((unsigned)(actual_len * sizeof(int))); + wca = (int *)alloc(actual_len * sizeof(int)); if (wca != NULL) { p = str; @@ -1230,7 +1230,7 @@ ins_compl_dictionaries( if (pat_esc == NULL) goto theend; len = STRLEN(pat_esc) + 10; - ptr = alloc((unsigned)len); + ptr = alloc(len); if (ptr == NULL) { vim_free(pat_esc); diff --git a/src/main.c b/src/main.c index 79b484454..e1ddbf7e9 100644 --- a/src/main.c +++ b/src/main.c @@ -2300,7 +2300,7 @@ command_line_scan(mparm_T *parmp) } else a = argv[0]; - p = alloc((unsigned)(STRLEN(a) + 4)); + p = alloc(STRLEN(a) + 4); if (p == NULL) mch_exit(2); sprintf((char *)p, "so %s", a); @@ -2526,7 +2526,7 @@ scripterror: * one. */ if (parmp->n_commands > 0) { - p = alloc((unsigned)STRLEN(parmp->commands[0]) + 3); + p = alloc(STRLEN(parmp->commands[0]) + 3); if (p != NULL) { sprintf((char *)p, ":%s\r", parmp->commands[0]); @@ -4263,7 +4263,7 @@ sendToLocalVim(char_u *cmd, int asExpr, char_u **result) size_t len = STRLEN(cmd) + STRLEN(err) + 5; char_u *msg; - msg = alloc((unsigned)len); + msg = alloc(len); if (msg != NULL) vim_snprintf((char *)msg, len, "%s: \"%s\"", err, cmd); *result = msg; diff --git a/src/mbyte.c b/src/mbyte.c index 411c3d907..c7de94e2f 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4317,7 +4317,7 @@ enc_canonize(char_u *enc) } /* copy "enc" to allocated memory, with room for two '-' */ - r = alloc((unsigned)(STRLEN(enc) + 3)); + r = alloc(STRLEN(enc) + 3); if (r != NULL) { /* Make it all lower case and replace '_' with '-'. */ @@ -4603,7 +4603,7 @@ iconv_string( /* Allocate enough room for most conversions. When re-allocating * increase the buffer size. */ len = len + fromlen * 2 + 40; - p = alloc((unsigned)len); + p = alloc(len); if (p != NULL && done > 0) mch_memmove(p, result, done); vim_free(result); diff --git a/src/memfile.c b/src/memfile.c index 1827bcf2b..9a1b4cb1c 100644 --- a/src/memfile.c +++ b/src/memfile.c @@ -130,7 +130,7 @@ mf_open(char_u *fname, int flags) struct STATFS stf; #endif - if ((mfp = (memfile_T *)alloc((unsigned)sizeof(memfile_T))) == NULL) + if ((mfp = (memfile_T *)alloc(sizeof(memfile_T))) == NULL) return NULL; if (fname == NULL) /* no file for this memfile, use memory only */ @@ -893,7 +893,7 @@ mf_alloc_bhdr(memfile_T *mfp, int page_count) { bhdr_T *hp; - if ((hp = (bhdr_T *)alloc((unsigned)sizeof(bhdr_T))) != NULL) + if ((hp = (bhdr_T *)alloc(sizeof(bhdr_T))) != NULL) { if ((hp->bh_data = (char_u *)alloc(mfp->mf_page_size * page_count)) == NULL) @@ -1108,7 +1108,7 @@ mf_trans_add(memfile_T *mfp, bhdr_T *hp) if (hp->bh_bnum >= 0) /* it's already positive */ return OK; - if ((np = (NR_TRANS *)alloc((unsigned)sizeof(NR_TRANS))) == NULL) + if ((np = (NR_TRANS *)alloc(sizeof(NR_TRANS))) == NULL) return FAIL; /* diff --git a/src/memline.c b/src/memline.c index 46b5ce8c1..35b524e6b 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1189,7 +1189,7 @@ ml_recover(int checkext) * Allocate a buffer structure for the swap file that is used for recovery. * Only the memline and crypt information in it are really used. */ - buf = (buf_T *)alloc((unsigned)sizeof(buf_T)); + buf = (buf_T *)alloc(sizeof(buf_T)); if (buf == NULL) goto theend; @@ -1787,7 +1787,7 @@ recover_names( * Do the loop for every directory in 'directory'. * First allocate some memory to put the directory name in. */ - dir_name = alloc((unsigned)STRLEN(p_dir) + 1); + dir_name = alloc(STRLEN(p_dir) + 1); dirp = p_dir; while (dir_name != NULL && *dirp) { @@ -1913,7 +1913,7 @@ recover_names( { if (mch_stat((char *)swapname, &st) != -1) /* It exists! */ { - files = (char_u **)alloc((unsigned)sizeof(char_u *)); + files = (char_u **)alloc(sizeof(char_u *)); if (files != NULL) { files[0] = swapname; @@ -2015,7 +2015,7 @@ make_percent_swname(char_u *dir, char_u *name) f = fix_fname(name != NULL ? name : (char_u *)""); if (f != NULL) { - s = alloc((unsigned)(STRLEN(f) + 1)); + s = alloc(STRLEN(f) + 1); if (s != NULL) { STRCPY(s, f); @@ -2674,7 +2674,7 @@ add_text_props_for_append( if (new_prop_count == 0) return; // nothing to do new_len = *len + new_prop_count * sizeof(textprop_T); - new_line = alloc((unsigned)new_len); + new_line = alloc(new_len); if (new_line == NULL) return; mch_memmove(new_line, *line, *len); @@ -4201,7 +4201,7 @@ ml_add_stack(buf_T *buf) { CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */ - newstack = (infoptr_T *)alloc((unsigned)sizeof(infoptr_T) * + newstack = (infoptr_T *)alloc(sizeof(infoptr_T) * (buf->b_ml.ml_stack_size + STACK_INCR)); if (newstack == NULL) return -1; @@ -4596,7 +4596,7 @@ findswapname( * Isolate a directory name from *dirp and put it in dir_name. * First allocate some memory to put the directory name in. */ - dir_name = alloc((unsigned)STRLEN(*dirp) + 1); + dir_name = alloc(STRLEN(*dirp) + 1); if (dir_name == NULL) *dirp = NULL; else @@ -4920,9 +4920,9 @@ findswapname( { char_u *name; - name = alloc((unsigned)(STRLEN(fname) + name = alloc(STRLEN(fname) + STRLEN(_("Swap file \"")) - + STRLEN(_("\" already exists!")) + 5)); + + STRLEN(_("\" already exists!")) + 5); if (name != NULL) { STRCPY(name, _("Swap file \"")); @@ -5371,8 +5371,8 @@ ml_updatechunk( return; if (buf->b_ml.ml_chunksize == NULL) { - buf->b_ml.ml_chunksize = (chunksize_T *) - alloc((unsigned)sizeof(chunksize_T) * 100); + buf->b_ml.ml_chunksize = + (chunksize_T *)alloc(sizeof(chunksize_T) * 100); if (buf->b_ml.ml_chunksize == NULL) { buf->b_ml.ml_usedchunks = -1; diff --git a/src/menu.c b/src/menu.c index 6e0c02ec3..1ff45b98d 100644 --- a/src/menu.c +++ b/src/menu.c @@ -694,7 +694,7 @@ add_menu_path( * \'s and ^V's stripped out. But menu_path is a "raw" * string, so we must correct for special characters. */ - tearpath = alloc((unsigned int)STRLEN(menu_path) + TEAR_LEN + 2); + tearpath = alloc(STRLEN(menu_path) + TEAR_LEN + 2); if (tearpath != NULL) { char_u *s; @@ -780,7 +780,7 @@ add_menu_path( if (c != 0) { - menu->strings[i] = alloc((unsigned)(STRLEN(call_data) + 5 )); + menu->strings[i] = alloc(STRLEN(call_data) + 5); if (menu->strings[i] != NULL) { menu->strings[i][0] = c; @@ -1316,7 +1316,7 @@ set_context_in_menu_cmd( menu = root_menu; if (after_dot != arg) { - path_name = alloc((unsigned)(after_dot - arg)); + path_name = alloc(after_dot - arg); if (path_name == NULL) return NULL; vim_strncpy(path_name, arg, after_dot - arg - 1); diff --git a/src/message.c b/src/message.c index 0ddff8b31..f1801c326 100644 --- a/src/message.c +++ b/src/message.c @@ -437,7 +437,7 @@ get_emsg_source(void) if (sourcing_name != NULL && other_sourcing_name()) { p = (char_u *)_("Error detected while processing %s:"); - Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p))); + Buf = alloc(STRLEN(sourcing_name) + STRLEN(p)); if (Buf != NULL) sprintf((char *)Buf, (char *)p, sourcing_name); return Buf; @@ -462,7 +462,7 @@ get_emsg_lnum(void) && sourcing_lnum != 0) { p = (char_u *)_("line %4ld:"); - Buf = alloc((unsigned)(STRLEN(p) + 20)); + Buf = alloc(STRLEN(p) + 20); if (Buf != NULL) sprintf((char *)Buf, (char *)p, (long)sourcing_lnum); return Buf; diff --git a/src/misc1.c b/src/misc1.c index 550a7273e..bb82f0903 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -2180,7 +2180,7 @@ vim_getenv(char_u *name, int *mustfree) pend1 = remove_tail(p, pend, (char_u *)"MacOS"); if (pend1 != pend) { - pnew = alloc((unsigned)(pend1 - p) + 15); + pnew = alloc(pend1 - p + 15); if (pnew != NULL) { STRNCPY(pnew, p, (pend1 - p)); @@ -2341,7 +2341,7 @@ vim_setenv(char_u *name, char_u *val) * Putenv does not copy the string, it has to remain * valid. The allocated memory will never be freed. */ - envbuf = alloc((unsigned)(STRLEN(name) + STRLEN(val) + 2)); + envbuf = alloc(STRLEN(name) + STRLEN(val) + 2); if (envbuf != NULL) { sprintf((char *)envbuf, "%s=%s", name, val); @@ -3019,7 +3019,7 @@ concat_fnames(char_u *fname1, char_u *fname2, int sep) { char_u *dest; - dest = alloc((unsigned)(STRLEN(fname1) + STRLEN(fname2) + 3)); + dest = alloc(STRLEN(fname1) + STRLEN(fname2) + 3); if (dest != NULL) { STRCPY(dest, fname1); @@ -3040,7 +3040,7 @@ concat_str(char_u *str1, char_u *str2) char_u *dest; size_t l = STRLEN(str1); - dest = alloc((unsigned)(l + STRLEN(str2) + 1L)); + dest = alloc(l + STRLEN(str2) + 1L); if (dest != NULL) { STRCPY(dest, str1); @@ -3076,7 +3076,7 @@ FullName_save( if (fname == NULL) return NULL; - buf = alloc((unsigned)MAXPATHL); + buf = alloc(MAXPATHL); if (buf != NULL) { if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) @@ -4231,7 +4231,7 @@ addfile( if (ga_grow(gap, 1) == FAIL) return; - p = alloc((unsigned)(STRLEN(f) + 1 + isdir)); + p = alloc(STRLEN(f) + 1 + isdir); if (p == NULL) return; diff --git a/src/misc2.c b/src/misc2.c index dac66ffb2..ddb677c20 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -711,7 +711,7 @@ mem_pre_alloc_s(size_t *sizep) } static void -mem_pre_alloc_l(long_u *sizep) +mem_pre_alloc_l(size_t *sizep) { *sizep += sizeof(size_t); } @@ -796,7 +796,7 @@ vim_mem_profile_dump(void) #ifdef FEAT_EVAL int -alloc_does_fail(long_u size) +alloc_does_fail(size_t size) { if (alloc_fail_countdown == 0) { @@ -818,39 +818,39 @@ alloc_does_fail(long_u size) #define KEEP_ROOM_KB (KEEP_ROOM / 1024L) /* - * Note: if unsigned is 16 bits we can only allocate up to 64K with alloc(). - * Use lalloc for larger blocks. + * The normal way to allocate memory. This handles an out-of-memory situation + * as well as possible, still returns NULL when we're completely out. */ char_u * -alloc(unsigned size) +alloc(size_t size) { - return (lalloc((long_u)size, TRUE)); + return lalloc(size, TRUE); } /* * alloc() with an ID for alloc_fail(). */ char_u * -alloc_id(unsigned size, alloc_id_T id UNUSED) +alloc_id(size_t size, alloc_id_T id UNUSED) { #ifdef FEAT_EVAL - if (alloc_fail_id == id && alloc_does_fail((long_u)size)) + if (alloc_fail_id == id && alloc_does_fail(size)) return NULL; #endif - return (lalloc((long_u)size, TRUE)); + return lalloc(size, TRUE); } /* * Allocate memory and set all bytes to zero. */ char_u * -alloc_clear(unsigned size) +alloc_clear(size_t size) { char_u *p; - p = lalloc((long_u)size, TRUE); + p = lalloc(size, TRUE); if (p != NULL) - (void)vim_memset(p, 0, (size_t)size); + (void)vim_memset(p, 0, size); return p; } @@ -858,44 +858,26 @@ alloc_clear(unsigned size) * Same as alloc_clear() but with allocation id for testing */ char_u * -alloc_clear_id(unsigned size, alloc_id_T id UNUSED) +alloc_clear_id(size_t size, alloc_id_T id UNUSED) { #ifdef FEAT_EVAL - if (alloc_fail_id == id && alloc_does_fail((long_u)size)) + if (alloc_fail_id == id && alloc_does_fail(size)) return NULL; #endif return alloc_clear(size); } /* - * alloc() with check for maximum line length - */ - char_u * -alloc_check(unsigned size) -{ -#if !defined(UNIX) - if (sizeof(int) == 2 && size > 0x7fff) - { - /* Don't hide this message */ - emsg_silent = 0; - emsg(_("E340: Line is becoming too long")); - return NULL; - } -#endif - return (lalloc((long_u)size, TRUE)); -} - -/* * Allocate memory like lalloc() and set all bytes to zero. */ char_u * -lalloc_clear(long_u size, int message) +lalloc_clear(size_t size, int message) { char_u *p; p = (lalloc(size, message)); if (p != NULL) - (void)vim_memset(p, 0, (size_t)size); + (void)vim_memset(p, 0, size); return p; } @@ -904,21 +886,21 @@ lalloc_clear(long_u size, int message) * This is used often, KEEP IT FAST! */ char_u * -lalloc(long_u size, int message) +lalloc(size_t size, int message) { char_u *p; /* pointer to new storage space */ static int releasing = FALSE; /* don't do mf_release_all() recursive */ int try_again; #if defined(HAVE_AVAIL_MEM) - static long_u allocated = 0; /* allocated since last avail check */ + static size_t allocated = 0; /* allocated since last avail check */ #endif - /* Safety check for allocating zero bytes */ + // Safety check for allocating zero bytes if (size == 0) { - /* Don't hide this message */ + // Don't hide this message emsg_silent = 0; - siemsg(_("E341: Internal error: lalloc(%ld, )"), size); + iemsg(_("E341: Internal error: lalloc(0, )")); return NULL; } @@ -939,7 +921,7 @@ lalloc(long_u size, int message) * allocating KEEP_ROOM amount of memory. * 3. Strict check for available memory: call mch_avail_mem() */ - if ((p = (char_u *)malloc((size_t)size)) != NULL) + if ((p = (char_u *)malloc(size)) != NULL) { #ifndef HAVE_AVAIL_MEM /* 1. No check for available memory: Just return. */ @@ -983,7 +965,7 @@ lalloc(long_u size, int message) theend: #ifdef MEM_PROFILE - mem_post_alloc((void **)&p, (size_t)size); + mem_post_alloc((void **)&p, size); #endif return p; } @@ -993,13 +975,13 @@ theend: */ #if defined(FEAT_SIGNS) || defined(PROTO) char_u * -lalloc_id(long_u size, int message, alloc_id_T id UNUSED) +lalloc_id(size_t size, int message, alloc_id_T id UNUSED) { #ifdef FEAT_EVAL if (alloc_fail_id == id && alloc_does_fail(size)) return NULL; #endif - return (lalloc((long_u)size, message)); + return (lalloc(size, message)); } #endif @@ -1028,7 +1010,7 @@ mem_realloc(void *ptr, size_t size) * Did_outofmem_msg is reset when a character is read. */ void -do_outofmem_msg(long_u size) +do_outofmem_msg(size_t size) { if (!did_outofmem_msg) { @@ -1039,7 +1021,7 @@ do_outofmem_msg(long_u size) * message fails, e.g. when setting v:errmsg. */ did_outofmem_msg = TRUE; - semsg(_("E342: Out of memory! (allocating %lu bytes)"), size); + semsg(_("E342: Out of memory! (allocating %lu bytes)"), (long_u)size); } } @@ -1288,12 +1270,12 @@ free_all_mem(void) vim_strsave(char_u *string) { char_u *p; - unsigned len; + size_t len; - len = (unsigned)STRLEN(string) + 1; + len = STRLEN(string) + 1; p = alloc(len); if (p != NULL) - mch_memmove(p, string, (size_t)len); + mch_memmove(p, string, len); return p; } @@ -1308,7 +1290,7 @@ vim_strnsave(char_u *string, int len) { char_u *p; - p = alloc((unsigned)(len + 1)); + p = alloc((size_t)(len + 1)); if (p != NULL) { STRNCPY(p, string, len); @@ -1322,12 +1304,12 @@ vim_strnsave(char_u *string, int len) * Returns NULL when out of memory. */ char_u * -vim_memsave(char_u *p, int len) +vim_memsave(char_u *p, size_t len) { - char_u *ret = alloc((unsigned)len); + char_u *ret = alloc(len); if (ret != NULL) - mch_memmove(ret, p, (size_t)len); + mch_memmove(ret, p, len); return ret; } @@ -1622,7 +1604,7 @@ strup_save(char_u *orig) newl = utf_char2len(uc); if (newl != l) { - s = alloc((unsigned)STRLEN(res) + 1 + newl - l); + s = alloc(STRLEN(res) + 1 + newl - l); if (s == NULL) { vim_free(res); @@ -1689,7 +1671,7 @@ strlow_save(char_u *orig) newl = utf_char2len(lc); if (newl != l) { - s = alloc((unsigned)STRLEN(res) + 1 + newl - l); + s = alloc(STRLEN(res) + 1 + newl - l); if (s == NULL) { vim_free(res); @@ -2077,7 +2059,7 @@ ga_grow(garray_T *gap, int n) n = gap->ga_growsize; new_len = gap->ga_itemsize * (gap->ga_len + n); pp = (gap->ga_data == NULL) - ? alloc((unsigned)new_len) : vim_realloc(gap->ga_data, new_len); + ? alloc(new_len) : vim_realloc(gap->ga_data, new_len); if (pp == NULL) return FAIL; old_len = gap->ga_itemsize * gap->ga_maxlen; @@ -3261,7 +3243,7 @@ call_shell(char_u *cmd, int opt) if (ecmd == NULL) ecmd = cmd; } - ncmd = alloc((unsigned)(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1)); + ncmd = alloc(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1); if (ncmd != NULL) { STRCPY(ncmd, p_sxq); @@ -3896,7 +3878,7 @@ qsort( int i, j; int gap; - buf = alloc((unsigned)elm_size); + buf = alloc(elm_size); if (buf == NULL) return; @@ -4073,7 +4055,7 @@ putenv(const char *string) if (moreenv() < 0) return -1; } - p = (char *)alloc((unsigned)(strlen(string) + 1)); + p = (char *)alloc(strlen(string) + 1); if (p == NULL) /* not enough core */ return -1; environ[i + 1] = 0; /* new end of env. */ @@ -4121,13 +4103,13 @@ newenv(void) ; esize = i + EXTRASIZE + 1; - env = (char **)alloc((unsigned)(esize * sizeof (elem))); + env = (char **)alloc(esize * sizeof (elem)); if (env == NULL) return -1; for (i = 0; environ[i]; i++) { - elem = (char *)alloc((unsigned)(strlen(environ[i]) + 1)); + elem = (char *)alloc(strlen(environ[i]) + 1); if (elem == NULL) return -1; env[i] = elem; @@ -4310,7 +4292,7 @@ read_string(FILE *fd, int cnt) int c; /* allocate memory */ - str = alloc((unsigned)cnt + 1); + str = alloc(cnt + 1); if (str != NULL) { /* Read the string. Quit when running into the EOF. */ @@ -4593,7 +4575,7 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc) } } - *argv = (char **)alloc((unsigned)((*argc + 4) * sizeof(char *))); + *argv = (char **)alloc((*argc + 4) * sizeof(char *)); if (*argv == NULL) /* out of memory */ return FAIL; } diff --git a/src/netbeans.c b/src/netbeans.c index 7c2ab42b9..f1ba01a08 100644 --- a/src/netbeans.c +++ b/src/netbeans.c @@ -790,7 +790,7 @@ nb_reply_text(int cmdno, char_u *result) nbdebug(("REP %d: %s\n", cmdno, (char *)result)); - reply = alloc((unsigned)STRLEN(result) + 32); + reply = alloc(STRLEN(result) + 32); sprintf((char *)reply, "%d %s\n", cmdno, (char *)result); nb_send((char *)reply, "nb_reply_text"); @@ -819,7 +819,7 @@ nb_reply_nr(int cmdno, long result) static char_u * nb_quote(char_u *txt) { - char_u *buf = alloc((unsigned)(2 * STRLEN(txt) + 1)); + char_u *buf = alloc(2 * STRLEN(txt) + 1); char_u *p = txt; char_u *q = buf; @@ -951,7 +951,7 @@ nb_joinlines(linenr_T first, linenr_T other) len_first = (int)STRLEN(ml_get(first)); len_other = (int)STRLEN(ml_get(other)); - p = alloc((unsigned)(len_first + len_other + 1)); + p = alloc(len_first + len_other + 1); if (p != NULL) { mch_memmove(p, ml_get(first), len_first); @@ -1084,8 +1084,7 @@ nb_do_cmd( { len = get_buf_size(buf->bufp); nlines = buf->bufp->b_ml.ml_line_count; - text = alloc((unsigned)((len > 0) - ? ((len + nlines) * 2) : 4)); + text = alloc((len > 0) ? ((len + nlines) * 2) : 4); if (text == NULL) { nbdebug((" nb_do_cmd: getText has null text field\n")); @@ -1395,8 +1394,7 @@ nb_do_cmd( char_u *newline; /* Insert halfway a line. */ - newline = alloc_check( - (unsigned)(STRLEN(oldline) + len + 1)); + newline = alloc(STRLEN(oldline) + len + 1); if (newline != NULL) { mch_memmove(newline, oldline, (size_t)pos->col); @@ -456,7 +456,7 @@ shift_block(oparg_T *oap, int amount) /* if we're splitting a TAB, allow for it */ bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); len = (int)STRLEN(bd.textstart) + 1; - newp = alloc_check((unsigned)(bd.textcol + i + j + len)); + newp = alloc(bd.textcol + i + j + len); if (newp == NULL) return; vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); @@ -550,7 +550,7 @@ shift_block(oparg_T *oap, int amount) + fill + (unsigned)STRLEN(non_white) + 1; - newp = alloc_check(new_line_len); + newp = alloc(new_line_len); if (newp == NULL) return; mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); @@ -644,7 +644,7 @@ block_insert( count -= off; } - newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); + newp = alloc(STRLEN(oldp) + s_len + count + 1); if (newp == NULL) continue; @@ -1003,7 +1003,7 @@ get_register( #endif get_yank_register(name, 0); - reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); + reg = (yankreg_T *)alloc(sizeof(yankreg_T)); if (reg != NULL) { *reg = *y_current; @@ -1013,8 +1013,7 @@ get_register( if (reg->y_size == 0) reg->y_array = NULL; else - reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) - * reg->y_size)); + reg->y_array = (char_u **)alloc(sizeof(char_u *) * reg->y_size); if (reg->y_array != NULL) { for (i = 0; i < reg->y_size; ++i) @@ -1177,7 +1176,7 @@ stuff_yank(int regname, char_u *p) { free_yank_all(); if ((y_current->y_array = - (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) + (char_u **)alloc(sizeof(char_u *))) == NULL) { vim_free(p); return FAIL; @@ -1921,7 +1920,7 @@ op_delete(oparg_T *oap) // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; oldp = ml_get(lnum); - newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); + newp = alloc(STRLEN(oldp) + 1 - n); if (newp == NULL) continue; /* copy up to deleted part */ @@ -2227,7 +2226,7 @@ op_replace(oparg_T *oap, int c) oldp = ml_get_curline(); oldlen = STRLEN(oldp); - newp = alloc_check((unsigned)oldlen + 1 + n); + newp = alloc(oldlen + 1 + n); if (newp == NULL) continue; vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); @@ -2260,8 +2259,7 @@ op_replace(oparg_T *oap, int c) else { /* Replacing with \r or \n means splitting the line. */ - after_p = alloc_check( - (unsigned)(oldlen + 1 + n - STRLEN(newp))); + after_p = alloc(oldlen + 1 + n - STRLEN(newp)); if (after_p != NULL) STRMOVE(after_p, oldp); } @@ -2869,7 +2867,7 @@ op_change(oparg_T *oap) { /* Subsequent calls to ml_get() flush the firstline data - take a * copy of the inserted text. */ - if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) + if ((ins_text = alloc(ins_len + 1)) != NULL) { vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; @@ -2890,8 +2888,7 @@ op_change(oparg_T *oap) else vpos.coladd = 0; oldp = ml_get(linenr); - newp = alloc_check((unsigned)(STRLEN(oldp) - + vpos.coladd + ins_len + 1)); + newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); if (newp == NULL) continue; /* copy up to block start */ @@ -3494,8 +3491,7 @@ do_put( } if (y_array != NULL) break; - y_array = (char_u **)alloc((unsigned) - (y_size * sizeof(char_u *))); + y_array = (char_u **)alloc((y_size * sizeof(char_u *))); if (y_array == NULL) goto end; } @@ -3741,7 +3737,7 @@ do_put( /* insert the new text */ totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; - newp = alloc_check((unsigned)totlen + oldlen + 1); + newp = alloc(totlen + oldlen + 1); if (newp == NULL) break; /* copy part up to cursor to new line */ @@ -3868,7 +3864,7 @@ do_put( lnum++; continue; } - newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); + newp = alloc(STRLEN(oldp) + totlen + 1); if (newp == NULL) goto end; /* alloc() gave an error message */ mch_memmove(newp, oldp, (size_t)col); @@ -3920,7 +3916,7 @@ do_put( lnum = new_cursor.lnum; ptr = ml_get(lnum) + col; totlen = (int)STRLEN(y_array[y_size - 1]); - newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); + newp = alloc(STRLEN(ptr) + totlen + 1); if (newp == NULL) goto error; STRCPY(newp, y_array[y_size - 1]); @@ -3930,7 +3926,7 @@ do_put( vim_free(newp); oldp = ml_get(lnum); - newp = alloc_check((unsigned)(col + yanklen + 1)); + newp = alloc(col + yanklen + 1); if (newp == NULL) goto error; /* copy first part of line */ @@ -4563,7 +4559,7 @@ do_join( col = sumsize - currsize - spaces[count - 1]; /* allocate the space for the new line */ - newp = alloc_check((unsigned)(sumsize + 1)); + newp = alloc(sumsize + 1); cend = newp + sumsize; *cend = 0; @@ -5880,7 +5876,7 @@ do_addsub( * When there are many leading zeros it could be very long. * Allocate a bit too much. */ - buf1 = alloc((unsigned)length + NUMBUFLEN); + buf1 = alloc(length + NUMBUFLEN); if (buf1 == NULL) goto theend; ptr = buf1; @@ -6055,7 +6051,7 @@ read_viminfo_register(vir_T *virp, int force) */ if (set_prev) y_previous = y_current; - array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); + array = (char_u **)alloc(limit * sizeof(char_u *)); str = skipwhite(skiptowhite(str)); if (STRNCMP(str, "CHAR", 4) == 0) new_type = MCHAR; @@ -6076,7 +6072,7 @@ read_viminfo_register(vir_T *virp, int force) if (size == limit) { char_u **new_array = (char_u **) - alloc((unsigned)(limit * 2 * sizeof(char_u *))); + alloc(limit * 2 * sizeof(char_u *)); if (new_array == NULL) { @@ -6116,8 +6112,7 @@ read_viminfo_register(vir_T *virp, int force) else { /* Move the lines from array[] to y_array[]. */ - y_current->y_array = - (char_u **)alloc((unsigned)(size * sizeof(char_u *))); + y_current->y_array = (char_u **)alloc(size * sizeof(char_u *)); for (i = 0; i < size; i++) { if (y_current->y_array == NULL) @@ -6214,7 +6209,7 @@ handle_viminfo_register(garray_T *values, int force) y_ptr->y_array = NULL; return; } - y_ptr->y_array = (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); + y_ptr->y_array = (char_u **)alloc(linecount * sizeof(char_u *)); if (y_ptr->y_array == NULL) { y_ptr->y_size = 0; // ensure object state is consistent @@ -7145,7 +7140,7 @@ str_to_reg( } else extra = 0; - s = alloc((unsigned)(i + extra + 1)); + s = alloc(i + extra + 1); if (s == NULL) break; if (extra) diff --git a/src/option.c b/src/option.c index 39ef052ee..42a252e0f 100644 --- a/src/option.c +++ b/src/option.c @@ -3430,7 +3430,7 @@ set_init_1(int clean_arg) cdpath = vim_getenv((char_u *)"CDPATH", &mustfree); if (cdpath != NULL) { - buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2)); + buf = alloc((STRLEN(cdpath) << 1) + 2); if (buf != NULL) { buf[0] = ','; /* start with ",", current dir first */ @@ -7913,7 +7913,7 @@ skip: wp->w_p_cc_cols = NULL; else { - wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1)); + wp->w_p_cc_cols = (int *)alloc(sizeof(int) * (count + 1)); if (wp->w_p_cc_cols != NULL) { /* sort the columns for faster usage on screen redraw inside @@ -10053,8 +10053,8 @@ showoptions( #define INC 20 #define GAP 3 - items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) * - PARAM_COUNT)); + items = (struct vimoption **)alloc(sizeof(struct vimoption *) + * PARAM_COUNT); if (items == NULL) return; @@ -11941,7 +11941,7 @@ ExpandSettings( *num_file = num_term; else return OK; - *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *))); + *file = (char_u **)alloc(*num_file * sizeof(char_u *)); if (*file == NULL) { *file = (char_u **)""; @@ -11959,7 +11959,7 @@ ExpandOldSetting(int *num_file, char_u ***file) char_u *buf; *num_file = 0; - *file = (char_u **)alloc((unsigned)sizeof(char_u *)); + *file = (char_u **)alloc(sizeof(char_u *)); if (*file == NULL) return FAIL; @@ -12822,7 +12822,7 @@ tabstop_set(char_u *var, int **array) return FALSE; } - *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int))); + *array = (int *)alloc((valcount + 1) * sizeof(int)); if (*array == NULL) return FALSE; (*array)[0] = valcount; @@ -13045,7 +13045,7 @@ tabstop_copy(int *oldts) if (oldts == NULL) return NULL; - newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int))); + newts = (int *)alloc((oldts[0] + 1) * sizeof(int)); if (newts != NULL) for (t = 0; t <= oldts[0]; ++t) newts[t] = oldts[t]; diff --git a/src/os_amiga.c b/src/os_amiga.c index 4a6814cfc..ec392cd7f 100644 --- a/src/os_amiga.c +++ b/src/os_amiga.c @@ -1467,7 +1467,7 @@ mch_expandpath( { #endif /* hack to replace '*' by '#?' */ - starbuf = alloc((unsigned)(2 * STRLEN(pat) + 1)); + starbuf = alloc(2 * STRLEN(pat) + 1); if (starbuf == NULL) goto Return; for (sp = pat, dp = starbuf; *sp; ++sp) diff --git a/src/os_mswin.c b/src/os_mswin.c index fc6806d88..67989fe28 100644 --- a/src/os_mswin.c +++ b/src/os_mswin.c @@ -1466,8 +1466,8 @@ mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) char_u *port_name = utf16_to_enc(wport_name, NULL); if (printer_name != NULL && port_name != NULL) - prt_name = alloc((unsigned)(STRLEN(printer_name) - + STRLEN(port_name) + STRLEN(text))); + prt_name = alloc(STRLEN(printer_name) + + STRLEN(port_name) + STRLEN(text)); if (prt_name != NULL) wsprintf((char *)prt_name, (const char *)text, printer_name, port_name); @@ -2111,7 +2111,7 @@ Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) char *err = _(e_invexprmsg); size_t len = STRLEN(str) + STRLEN(err) + 5; - res = alloc((unsigned)len); + res = alloc(len); if (res != NULL) vim_snprintf((char *)res, len, "%s: \"%s\"", err, str); reply.dwData = COPYDATA_ERROR_RESULT; @@ -2340,7 +2340,7 @@ serverSetName(char_u *name) char_u *p; /* Leave enough space for a 9-digit suffix to ensure uniqueness! */ - ok_name = alloc((unsigned)STRLEN(name) + 10); + ok_name = alloc(STRLEN(name) + 10); STRCPY(ok_name, name); p = ok_name + STRLEN(name); diff --git a/src/os_unix.c b/src/os_unix.c index a6d1a12d1..0ec48a112 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2447,7 +2447,8 @@ strerror(int err) #endif /* - * Get name of current directory into buffer 'buf' of length 'len' bytes. + * Get name of current directory into buffer "buf" of length "len" bytes. + * "len" must be at least PATH_MAX. * Return OK for success, FAIL for failure. */ int @@ -2516,7 +2517,7 @@ mch_FullName( { /* * If the file name has a path, change to that directory for a moment, - * and then do the getwd() (and get back to where we were). + * and then get the directory (and get back to where we were). * This will get the correct path name with "../" things. */ if (p != NULL) @@ -3124,7 +3125,7 @@ mch_can_exe(char_u *name, char_u **path, int use_path) p = (char_u *)getenv("PATH"); if (p == NULL || *p == NUL) return -1; - buf = alloc((unsigned)(STRLEN(name) + STRLEN(p) + 2)); + buf = alloc(STRLEN(name) + STRLEN(p) + 2); if (buf == NULL) return -1; @@ -4323,7 +4324,7 @@ build_argv( /* Break 'shellcmdflag' into white separated parts. This doesn't * handle quoted strings, they are very unlikely to appear. */ - *shcf_tofree = alloc((unsigned)STRLEN(p_shcf) + 1); + *shcf_tofree = alloc(STRLEN(p_shcf) + 1); if (*shcf_tofree == NULL) /* out of memory */ return FAIL; s = *shcf_tofree; @@ -6899,7 +6900,7 @@ mch_expand_wildcards( && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) continue; - p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); + p = alloc(STRLEN((*file)[i]) + 1 + dir); if (p) { STRCPY(p, (*file)[i]); diff --git a/src/os_vms.c b/src/os_vms.c index 61db3a80b..ca04019d2 100644 --- a/src/os_vms.c +++ b/src/os_vms.c @@ -238,7 +238,7 @@ mch_getenv(char_u *lognam) if (sys$trnlnm(&attrib, &d_file_dev, &d_lognam, NULL,&itmlst) == SS$_NORMAL) { buffer[lengte] = '\0'; - if (cp = (char_u *)alloc((unsigned)(lengte+1))) + if (cp = (char_u *)alloc(lengte + 1)) strcpy((char *)cp, buffer); return(cp); } diff --git a/src/os_win32.c b/src/os_win32.c index 237de979e..d2907102e 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -2075,8 +2075,7 @@ executable_exists(char *name, char_u **path, int use_path) return FALSE; wcurpath = _wgetenv(L"PATH"); - wnewpath = (WCHAR*)alloc((unsigned)(wcslen(wcurpath) + 3) - * sizeof(WCHAR)); + wnewpath = (WCHAR *)alloc((wcslen(wcurpath) + 3) * sizeof(WCHAR)); if (wnewpath == NULL) return FALSE; wcscpy(wnewpath, L".;"); @@ -7205,7 +7204,7 @@ mch_setenv(char *var, char *value, int x) char_u *envbuf; WCHAR *p; - envbuf = alloc((unsigned)(STRLEN(var) + STRLEN(value) + 2)); + envbuf = alloc(STRLEN(var) + STRLEN(value) + 2); if (envbuf == NULL) return -1; diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro index 566c97309..687cfedaf 100644 --- a/src/proto/misc2.pro +++ b/src/proto/misc2.pro @@ -20,21 +20,20 @@ void check_cursor(void); void adjust_cursor_col(void); int leftcol_changed(void); void vim_mem_profile_dump(void); -int alloc_does_fail(long_u size); -char_u *alloc(unsigned size); -char_u *alloc_id(unsigned size, alloc_id_T id); -char_u *alloc_clear(unsigned size); -char_u *alloc_clear_id(unsigned size, alloc_id_T id); -char_u *alloc_check(unsigned size); -char_u *lalloc_clear(long_u size, int message); -char_u *lalloc(long_u size, int message); -char_u *lalloc_id(long_u size, int message, alloc_id_T id); +int alloc_does_fail(size_t size); +char_u *alloc(size_t size); +char_u *alloc_id(size_t size, alloc_id_T id); +char_u *alloc_clear(size_t size); +char_u *alloc_clear_id(size_t size, alloc_id_T id); +char_u *lalloc_clear(size_t size, int message); +char_u *lalloc(size_t size, int message); +char_u *lalloc_id(size_t size, int message, alloc_id_T id); void *mem_realloc(void *ptr, size_t size); -void do_outofmem_msg(long_u size); +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, 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); diff --git a/src/quickfix.c b/src/quickfix.c index cf3b27484..46eae2dd2 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -1346,7 +1346,7 @@ qf_parse_multiline_pfx( if (*fields->errmsg && !qfl->qf_multiignore) { len = (int)STRLEN(qfprev->qf_text); - if ((ptr = alloc((unsigned)(len + STRLEN(fields->errmsg) + 2))) + if ((ptr = alloc(len + STRLEN(fields->errmsg) + 2)) == NULL) return QF_FAIL; STRCPY(ptr, qfprev->qf_text); @@ -1890,7 +1890,7 @@ locstack_queue_delreq(qf_info_T *qi) { qf_delq_T *q; - q = (qf_delq_T *)alloc((unsigned)sizeof(qf_delq_T)); + q = (qf_delq_T *)alloc(sizeof(qf_delq_T)); if (q != NULL) { q->qi = qi; @@ -2063,7 +2063,7 @@ qf_add_entry( qfline_T *qfp; qfline_T **lastp; // pointer to qf_last or NULL - if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) + if ((qfp = (qfline_T *)alloc(sizeof(qfline_T))) == NULL) return QF_FAIL; if (bufnum != 0) { @@ -2429,7 +2429,7 @@ qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr, int is_file_stack) struct dir_stack_T *ds_ptr; // allocate new stack element and hook it in - ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); + ds_new = (struct dir_stack_T *)alloc(sizeof(struct dir_stack_T)); if (ds_new == NULL) return NULL; @@ -4707,7 +4707,7 @@ get_mef_name(void) else off += 19; - name = alloc((unsigned)STRLEN(p_mef) + 30); + name = alloc(STRLEN(p_mef) + 30); if (name == NULL) break; STRCPY(name, p_mef); diff --git a/src/regexp.c b/src/regexp.c index ee485a3ab..3697cd983 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -7145,7 +7145,7 @@ regtilde(char_u *source, int magic) { /* length = len(newsub) - 1 + len(prev_sub) + 1 */ prevlen = (int)STRLEN(reg_prev_sub); - tmpsub = alloc((unsigned)(STRLEN(newsub) + prevlen)); + tmpsub = alloc(STRLEN(newsub) + prevlen); if (tmpsub != NULL) { /* copy prefix */ diff --git a/src/screen.c b/src/screen.c index e6c0b2b3d..cb10f6ee9 100644 --- a/src/screen.c +++ b/src/screen.c @@ -4948,7 +4948,7 @@ win_line( if (n_extra > 0) len += n_extra - tab_len; c = lcs_tab1; - p = alloc((unsigned)(len + 1)); + p = alloc(len + 1); vim_memset(p, ' ', len); p[len] = NUL; vim_free(p_extra_free); @@ -5107,7 +5107,7 @@ win_line( char_u *p; c = *p_extra; - p = alloc((unsigned)n_extra + 1); + p = alloc(n_extra + 1); vim_memset(p, ' ', n_extra); STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); p[n_extra] = NUL; @@ -6680,9 +6680,9 @@ win_redr_status_matches( return; if (has_mbyte) - buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); + buf = alloc(Columns * MB_MAXBYTES + 1); else - buf = alloc((unsigned)Columns + 1); + buf = alloc(Columns + 1); if (buf == NULL) return; diff --git a/src/spell.c b/src/spell.c index fbe20802c..fa5be8be1 100644 --- a/src/spell.c +++ b/src/spell.c @@ -2083,7 +2083,7 @@ count_common_word( hi = hash_lookup(&lp->sl_wordcount, p, hash); if (HASHITEM_EMPTY(hi)) { - wc = (wordcount_T *)alloc((unsigned)(sizeof(wordcount_T) + STRLEN(p))); + wc = (wordcount_T *)alloc(sizeof(wordcount_T) + STRLEN(p)); if (wc == NULL) return; STRCPY(wc->wc_word, p); @@ -3432,8 +3432,7 @@ spell_suggest(int count) } /* Replace the word. */ - p = alloc((unsigned)STRLEN(line) - stp->st_orglen - + stp->st_wordlen + 1); + p = alloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1); if (p != NULL) { c = (int)(sug.su_badptr - line); @@ -3552,7 +3551,7 @@ ex_spellrepall(exarg_T *eap UNUSED) } addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); - frompat = alloc((unsigned)STRLEN(repl_from) + 7); + frompat = alloc(STRLEN(repl_from) + 7); if (frompat == NULL) return; sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); @@ -3573,7 +3572,7 @@ ex_spellrepall(exarg_T *eap UNUSED) if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, repl_to, STRLEN(repl_to)) != 0) { - p = alloc((unsigned)STRLEN(line) + addlen + 1); + p = alloc(STRLEN(line) + addlen + 1); if (p == NULL) break; mch_memmove(p, line, curwin->w_cursor.col); @@ -6224,8 +6223,7 @@ add_sound_suggest( hi = hash_lookup(&slang->sl_sounddone, goodword, hash); if (HASHITEM_EMPTY(hi)) { - sft = (sftword_T *)alloc((unsigned)(sizeof(sftword_T) - + STRLEN(goodword))); + sft = (sftword_T *)alloc(sizeof(sftword_T) + STRLEN(goodword)); if (sft != NULL) { sft->sft_score = score; diff --git a/src/spellfile.c b/src/spellfile.c index 00c72f6f1..06cf1bcab 100644 --- a/src/spellfile.c +++ b/src/spellfile.c @@ -1264,7 +1264,7 @@ read_compound(FILE *fd, slang_T *slang, int len) c = todo * 2 + 7; if (enc_utf8) c += todo * 2; - pat = alloc((unsigned)c); + pat = alloc(c); if (pat == NULL) return SP_OTHERERROR; @@ -6615,7 +6615,7 @@ set_map_str(slang_T *lp, char_u *map) hash_T hash; hashitem_T *hi; - b = alloc((unsigned)(cl + headcl + 2)); + b = alloc(cl + headcl + 2); if (b == NULL) return; mb_char2bytes(c, b); diff --git a/src/syntax.c b/src/syntax.c index 09491450b..27a64c226 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -4757,7 +4757,7 @@ syn_incl_toplevel(int id, int *flagsp) if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) { /* We have to alloc this, because syn_combine_list() will free it. */ - short *grp_list = (short *)alloc((unsigned)(2 * sizeof(short))); + short *grp_list = (short *)alloc(2 * sizeof(short)); int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; if (grp_list != NULL) @@ -4872,7 +4872,7 @@ syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) syn_id = syn_check_group(arg, (int)(group_name_end - arg)); if (syn_id != 0) /* allocate a buffer, for removing backslashes in the keyword */ - keyword_copy = alloc((unsigned)STRLEN(rest) + 1); + keyword_copy = alloc(STRLEN(rest) + 1); if (keyword_copy != NULL) { syn_opt_arg.flags = 0; @@ -5208,7 +5208,7 @@ syn_cmd_region( * syn_patterns for this item, at the start (because the list is * used from end to start). */ - ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); + ppp = (struct pat_ptr *)alloc(sizeof(struct pat_ptr)); if (ppp == NULL) { rest = NULL; @@ -5465,7 +5465,7 @@ syn_combine_list(short **clstr1, short **clstr2, int list_op) clstr = NULL; break; } - clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); + clstr = (short *)alloc((count + 1) * sizeof(short)); if (clstr == NULL) break; clstr[count] = 0; @@ -6124,7 +6124,7 @@ get_id_list( break; if (round == 1) { - retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); + retval = (short *)alloc((count + 1) * sizeof(short)); if (retval == NULL) break; retval[count] = 0; /* zero means end of the list */ @@ -6163,7 +6163,7 @@ copy_id_list(short *list) for (count = 0; list[count]; ++count) ; len = (count + 1) * sizeof(short); - retval = (short *)alloc((unsigned)len); + retval = (short *)alloc(len); if (retval != NULL) mch_memmove(retval, list, (size_t)len); @@ -7167,7 +7167,7 @@ load_colors(char_u *name) return OK; recursive = TRUE; - buf = alloc((unsigned)(STRLEN(name) + 12)); + buf = alloc(STRLEN(name) + 12); if (buf != NULL) { apply_autocmds(EVENT_COLORSCHEMEPRE, name, diff --git a/src/term.c b/src/term.c index fb002ec81..9885fecfd 100644 --- a/src/term.c +++ b/src/term.c @@ -6165,7 +6165,7 @@ replace_termcodes( * Allocate space for the translation. Worst case a single character is * replaced by 6 bytes (shifted special key), plus a NUL at the end. */ - result = alloc((unsigned)STRLEN(from) * 6 + 1); + result = alloc(STRLEN(from) * 6 + 1); if (result == NULL) /* out of memory */ { *bufp = NULL; @@ -6420,7 +6420,7 @@ show_termcodes(void) if (tc_len == 0) /* no terminal codes (must be GUI) */ return; - items = (int *)alloc((unsigned)(sizeof(int) * tc_len)); + items = (int *)alloc(sizeof(int) * tc_len); if (items == NULL) return; diff --git a/src/undo.c b/src/undo.c index c4558d1c7..ed2cd58fe 100644 --- a/src/undo.c +++ b/src/undo.c @@ -367,6 +367,8 @@ u_save_line(undoline_T *ul, linenr_T lnum) } else { + // This uses the length in the memline, thus text properties are + // included. ul->ul_len = curbuf->b_ml.ml_line_len; ul->ul_line = vim_memsave(line, ul->ul_len); } @@ -1121,7 +1123,7 @@ undo_read(bufinfo_T *bi, char_u *buffer, size_t size) static char_u * read_string_decrypt(bufinfo_T *bi, int len) { - char_u *ptr = alloc((unsigned)len + 1); + char_u *ptr = alloc(len + 1); if (ptr != NULL) { @@ -2689,7 +2691,8 @@ u_undoredo(int undo) char_u *p = ml_get(top + 1 + i); if (curbuf->b_ml.ml_line_len != uep->ue_array[i].ul_len - || memcmp(uep->ue_array[i].ul_line, p, curbuf->b_ml.ml_line_len) != 0) + || memcmp(uep->ue_array[i].ul_line, p, + curbuf->b_ml.ml_line_len) != 0) break; } if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL) @@ -2750,9 +2753,11 @@ u_undoredo(int undo) // If the file is empty, there is an empty line 1 that we // should get rid of, by replacing it with the new line. if (empty_buffer && lnum == 0) - ml_replace_len((linenr_T)1, uep->ue_array[i].ul_line, uep->ue_array[i].ul_len, TRUE, TRUE); + ml_replace_len((linenr_T)1, uep->ue_array[i].ul_line, + uep->ue_array[i].ul_len, TRUE, TRUE); else - ml_append(lnum, uep->ue_array[i].ul_line, (colnr_T)uep->ue_array[i].ul_len, FALSE); + ml_append(lnum, uep->ue_array[i].ul_line, + (colnr_T)uep->ue_array[i].ul_len, FALSE); vim_free(uep->ue_array[i].ul_line); } vim_free((char_u *)uep->ue_array); diff --git a/src/usercmd.c b/src/usercmd.c index 45d7ea052..e5c3a3e46 100644 --- a/src/usercmd.c +++ b/src/usercmd.c @@ -1637,7 +1637,7 @@ do_ucmd(exarg_T *eap) } totlen += STRLEN(p); // Add on the trailing characters - buf = alloc((unsigned)(totlen + 1)); + buf = alloc(totlen + 1); if (buf == NULL) { vim_free(split_buf); diff --git a/src/userfunc.c b/src/userfunc.c index 763903f85..dcf803401 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -557,7 +557,7 @@ fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error) } else { - fname = alloc((unsigned)(i + STRLEN(name + llen) + 1)); + fname = alloc(i + STRLEN(name + llen) + 1); if (fname == NULL) *error = ERROR_OTHER; else @@ -978,7 +978,7 @@ call_user_func( /* need space for function name + ("function " + 3) or "[number]" */ len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) + STRLEN(fp->uf_name) + 20; - sourcing_name = alloc((unsigned)len); + sourcing_name = alloc(len); if (sourcing_name != NULL) { if (save_sourcing_name != NULL @@ -1932,7 +1932,7 @@ trans_function_name( } } - name = alloc((unsigned)(len + lead + 1)); + name = alloc(len + lead + 1); if (name != NULL) { if (lead > 0) @@ -2787,7 +2787,7 @@ func_dump_profile(FILE *fd) if (todo == 0) return; /* nothing to dump */ - sorttab = (ufunc_T **)alloc((unsigned)(sizeof(ufunc_T *) * todo)); + sorttab = (ufunc_T **)alloc(sizeof(ufunc_T *) * todo); for (hi = func_hashtab.ht_array; todo > 0; ++hi) { diff --git a/src/version.c b/src/version.c index b774f3d7d..678d7e8fb 100644 --- a/src/version.c +++ b/src/version.c @@ -61,7 +61,7 @@ init_longVersion(void) + strlen(VIM_VERSION_DATE_ONLY) + strlen(date_time); - longVersion = (char *)alloc((unsigned)len); + longVersion = (char *)alloc(len); if (longVersion == NULL) longVersion = VIM_VERSION_LONG; else @@ -768,6 +768,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1384, +/**/ 1383, /**/ 1382, diff --git a/src/winclip.c b/src/winclip.c index 4d0a2c38c..feef18d3c 100644 --- a/src/winclip.c +++ b/src/winclip.c @@ -169,7 +169,7 @@ WideCharToMultiByte_alloc(UINT cp, DWORD flags, { *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); /* Add one one byte to avoid a zero-length alloc(). */ - *out = (LPSTR)alloc((unsigned)*outlen + 1); + *out = (LPSTR)alloc(*outlen + 1); if (*out != NULL) { WideCharToMultiByte(cp, flags, in, inlen, *out, *outlen, def, useddef); @@ -512,8 +512,7 @@ clip_mch_set_selection(VimClipboard *cbd) metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, NULL, 0, 0, 0); vim_free(str); - str = (char_u *)alloc((unsigned)(metadata.txtlen == 0 ? 1 - : metadata.txtlen)); + str = (char_u *)alloc(metadata.txtlen == 0 ? 1 : metadata.txtlen); if (str == NULL) { vim_free(out); @@ -655,7 +654,7 @@ enc_to_utf16(char_u *str, int *lenp) convert_setup(&conv, NULL, NULL); length = utf8_to_utf16(str, *lenp, NULL, NULL); - ret = (WCHAR *)alloc((unsigned)((length + 1) * sizeof(WCHAR))); + ret = (WCHAR *)alloc((length + 1) * sizeof(WCHAR)); if (ret != NULL) { utf8_to_utf16(str, *lenp, (short_u *)ret, NULL); |