From 964b3746b9c81e65887e2ac9a335f181db2bb592 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 24 May 2019 18:54:09 +0200 Subject: patch 8.1.1384: using "int" for alloc() often results in compiler warnings 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. --- src/autocmd.c | 8 ++-- src/buffer.c | 4 +- src/change.c | 6 +-- src/channel.c | 4 +- src/charset.c | 4 +- src/debugger.c | 2 +- src/dict.c | 5 +-- src/diff.c | 6 +-- src/digraph.c | 2 +- src/edit.c | 2 +- src/eval.c | 15 ++++---- src/evalfunc.c | 20 +++++----- src/ex_cmds.c | 16 ++++---- src/ex_cmds2.c | 2 +- src/ex_docmd.c | 12 +++--- src/ex_eval.c | 6 +-- src/ex_getln.c | 14 +++---- src/fileio.c | 10 ++--- src/findfile.c | 17 ++++----- src/fold.c | 4 +- src/getchar.c | 6 +-- src/gui.c | 4 +- src/gui_at_fs.c | 6 +-- src/gui_gtk.c | 2 +- src/gui_gtk_x11.c | 9 ++--- src/gui_motif.c | 2 +- src/gui_w32.c | 6 +-- src/hashtab.c | 3 +- src/if_cscope.c | 22 +++++------ src/if_perlsfio.c | 2 +- src/if_python3.c | 2 +- src/if_xcmdsrv.c | 4 +- src/indent.c | 2 +- src/insexpand.c | 4 +- src/main.c | 6 +-- src/mbyte.c | 4 +- src/memfile.c | 6 +-- src/memline.c | 22 +++++------ src/menu.c | 6 +-- src/message.c | 4 +- src/misc1.c | 12 +++--- src/misc2.c | 106 ++++++++++++++++++++++------------------------------ src/netbeans.c | 12 +++--- src/ops.c | 51 ++++++++++++------------- src/option.c | 16 ++++---- src/os_amiga.c | 2 +- src/os_mswin.c | 8 ++-- src/os_unix.c | 11 +++--- src/os_vms.c | 2 +- src/os_win32.c | 5 +-- src/proto/misc2.pro | 21 +++++------ src/quickfix.c | 10 ++--- src/regexp.c | 2 +- src/screen.c | 8 ++-- src/spell.c | 12 +++--- src/spellfile.c | 4 +- src/syntax.c | 14 +++---- src/term.c | 4 +- src/undo.c | 13 +++++-- src/usercmd.c | 2 +- src/userfunc.c | 8 ++-- src/version.c | 4 +- src/winclip.c | 7 ++-- 63 files changed, 293 insertions(+), 322 deletions(-) diff --git a/src/autocmd.c b/src/autocmd.c index e6cdb361ed..614bc331f5 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 425c9143a1..d99071674f 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 b43ba35745..d2aa1530f1 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 31c9bbe229..1564128efb 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 cff62e1857..171eccbfce 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 78e32d33dc..b79f61365a 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -873,7 +873,7 @@ debuggy_find( // Replace K_SNR in function name with "". 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 007a7ff851..6e1d0d640f 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 38ae0b47c9..3c72e12bf8 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 d936136805..a26d10ca05 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 8a008cbfd4..6e2fdb8448 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 6950348999..4796a25bb3 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 6ffd1a1abf..58ea7103fc 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 040514cdc5..7420d6752a 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 59452032bd..c56e305336 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 f4f7639e77..c6e00bec51 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 63bca67180..b1bb7e5ddb 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 ba3dc7358a..00193fee88 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 57c5f47fc6..e41f967622 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 3d3aec0df9..a6d164ad29 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 7446f7c632..4cc7a477d7 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 debad7efd2..0ebe715cd4 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; diff --git a/src/gui.c b/src/gui.c index 8568c20454..8edc86cd76 100644 --- a/src/gui.c +++ b/src/gui.c @@ -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 e65a26648c..c50816b82a 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 126eaf06d9..8537060279 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 7d1d8d0c51..17ef6eabdc 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 421733933a..1693df974d 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 5961830737..bf27386061 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 6f2c2ca7b5..54f7500c24 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 93a0458b4f..4d5748910b 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 528a1b4f11..31f0c6b3e2 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 d93d633186..823cfea3bd 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 430548eb35..4b44126d59 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 893ca298c0..8499b81347 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 eeff64ca2c..4a807f48c8 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 79b4844540..e1ddbf7e9a 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 411c3d907d..c7de94e2f6 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 1827bcf2b3..9a1b4cb1c6 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 46b5ce8c17..35b524e6b2 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 6e0c02ec3b..1ff45b98da 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 0ddff8b310..f1801c3269 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 550a7273e2..bb82f0903a 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 dac66ffb28..ddb677c20e 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 7c2ab42b9b..f1ba01a082 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); diff --git a/src/ops.c b/src/ops.c index 4d2692483b..f1e6a63b23 100644 --- a/src/ops.c +++ b/src/ops.c @@ -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 39ef052eea..42a252e0f6 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)