Skip to content

Commit

Permalink
patch 8.1.1393: unnecessary type casts
Browse files Browse the repository at this point in the history
Problem:    Unnecessary type casts.
Solution:   Remove type casts from alloc() and lalloc() calls. (Mike Williams)
  • Loading branch information
brammool committed May 25, 2019
1 parent 682725c commit 51e1438
Show file tree
Hide file tree
Showing 31 changed files with 70 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ channel_set_req_callback(
int id)
{
cbq_T *head = &channel->ch_part[part].ch_cb_head;
cbq_T *item = (cbq_T *)alloc((int)sizeof(cbq_T));
cbq_T *item = (cbq_T *)alloc(sizeof(cbq_T));

if (item != NULL)
{
Expand Down Expand Up @@ -3921,7 +3921,7 @@ channel_send(
}
else
{
writeq_T *last = (writeq_T *)alloc((int)sizeof(writeq_T));
writeq_T *last = (writeq_T *)alloc(sizeof(writeq_T));

if (last != NULL)
{
Expand Down
4 changes: 2 additions & 2 deletions src/crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ crypt_create(
char_u *seed,
int seed_len)
{
cryptstate_T *state = (cryptstate_T *)alloc((int)sizeof(cryptstate_T));
cryptstate_T *state = (cryptstate_T *)alloc(sizeof(cryptstate_T));

if (state == NULL)
return state;
Expand Down Expand Up @@ -407,7 +407,7 @@ crypt_encode_alloc(
/* Not buffering, just return EOF. */
return (long)len;

*newptr = alloc((long)len);
*newptr = alloc(len);
if (*newptr == NULL)
return -1;
method->encode_fn(state, from, len, *newptr);
Expand Down
2 changes: 1 addition & 1 deletion src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dict_alloc(void)
dict_alloc_id(alloc_id_T id UNUSED)
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T)))
if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T)))
return NULL;
#endif
return (dict_alloc());
Expand Down
8 changes: 4 additions & 4 deletions src/dosinst.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ findoldfile(char **destination)
|| strchr(cp, '/') != NULL)
return;

tmpname = alloc((int)strlen(cp) + 1);
tmpname = alloc(strlen(cp) + 1);
strcpy(tmpname, cp);
tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */

Expand Down Expand Up @@ -962,7 +962,7 @@ alloc_text(int idx, char *fmt, char *arg)
if (choices[idx].text != NULL)
free(choices[idx].text);

choices[idx].text = alloc((int)(strlen(fmt) + strlen(arg)) - 1);
choices[idx].text = alloc(strlen(fmt) + strlen(arg) - 1);
sprintf(choices[idx].text, fmt, arg);
}

Expand Down Expand Up @@ -1040,7 +1040,7 @@ change_bat_choice(int idx)
s = p + strlen(p);
if (names != NULL)
{
names[count] = alloc((int)(s - p) + 1);
names[count] = alloc(s - p + 1);
strncpy(names[count], p, s - p);
names[count][s - p] = NUL;
}
Expand All @@ -1051,7 +1051,7 @@ change_bat_choice(int idx)
}
if (names != NULL)
break;
names = alloc((int)(count + 1) * sizeof(char *));
names = alloc((count + 1) * sizeof(char *));
}
names[0] = alloc(50);
sprintf(names[0], "Select directory to create %s in:", name);
Expand Down
4 changes: 2 additions & 2 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4412,7 +4412,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref)
* would also work, but some plugins depend on the name being
* printable text. */
sprintf(sid_buf, "<SNR>%ld_", (long)current_sctx.sc_sid);
name = alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1));
name = alloc(STRLEN(sid_buf) + STRLEN(s + off) + 1);
if (name != NULL)
{
STRCPY(name, sid_buf);
Expand Down Expand Up @@ -12671,7 +12671,7 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
}

/* Make an array with each entry pointing to an item in the List. */
ptrs = (sortItem_T *)alloc((int)(len * sizeof(sortItem_T)));
ptrs = (sortItem_T *)alloc(len * sizeof(sortItem_T));
if (ptrs == NULL)
goto theend;

Expand Down
2 changes: 1 addition & 1 deletion src/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ barline_parse(vir_T *virp, char_u *text, garray_T *values)
*/
++p;
len = getdigits(&p);
buf = alloc((int)(len + 1));
buf = alloc(len + 1);
if (buf == NULL)
return TRUE;
p = buf;
Expand Down
2 changes: 1 addition & 1 deletion src/ex_cmds2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@ add_pack_dir_to_rtp(char_u *fname)

oldlen = STRLEN(p_rtp);
addlen = STRLEN(fname) + 1; // add one for comma
new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); // add one for NUL
new_rtp = alloc(oldlen + addlen + afterlen + 1); // add one for NUL
if (new_rtp == NULL)
goto theend;

Expand Down
4 changes: 2 additions & 2 deletions src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4816,7 +4816,7 @@ replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep)
while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL)
++i;
len = (int)STRLEN(p);
new_cmdline = alloc((int)(STRLEN(program) + i * (len - 2) + 1));
new_cmdline = alloc(STRLEN(program) + i * (len - 2) + 1);
if (new_cmdline == NULL)
return NULL; /* out of memory */
ptr = new_cmdline;
Expand All @@ -4832,7 +4832,7 @@ replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep)
}
else
{
new_cmdline = alloc((int)(STRLEN(program) + STRLEN(p) + 2));
new_cmdline = alloc(STRLEN(program) + STRLEN(p) + 2);
if (new_cmdline == NULL)
return NULL; /* out of memory */
STRCPY(new_cmdline, program);
Expand Down
5 changes: 2 additions & 3 deletions src/ex_getln.c
Original file line number Diff line number Diff line change
Expand Up @@ -5914,8 +5914,7 @@ init_history(void)
{
if (newlen)
{
temp = (histentry_T *)alloc(
(long_u)(newlen * sizeof(histentry_T)));
temp = (histentry_T *)alloc(newlen * sizeof(histentry_T));
if (temp == NULL) /* out of memory! */
{
if (type == 0) /* first one: just keep the old length */
Expand Down Expand Up @@ -6655,7 +6654,7 @@ prepare_viminfo_history(int asklen, int writing)
viminfo_history[type] = NULL;
else
viminfo_history[type] = (histentry_T *)lalloc(
(long_u)(len * sizeof(histentry_T)), FALSE);
len * sizeof(histentry_T), FALSE);
if (viminfo_history[type] == NULL)
len = 0;
viminfo_hislen[type] = len;
Expand Down
2 changes: 1 addition & 1 deletion src/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -7190,7 +7190,7 @@ readdir_core(
ga_init2(gap, (int)sizeof(char *), 20);

#ifdef MSWIN
buf = alloc((int)MAXPATHL);
buf = alloc(MAXPATHL);
if (buf == NULL)
return FAIL;
STRNCPY(buf, path, MAXPATHL-5);
Expand Down
14 changes: 7 additions & 7 deletions src/findfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ vim_findfile_init(
if (search_ctx->ffsc_wc_path != NULL)
{
wc_path = vim_strsave(search_ctx->ffsc_wc_path);
temp = alloc((int)(STRLEN(search_ctx->ffsc_wc_path)
temp = alloc(STRLEN(search_ctx->ffsc_wc_path)
+ STRLEN(search_ctx->ffsc_fix_path + len)
+ 1));
+ 1);
if (temp == NULL || wc_path == NULL)
{
vim_free(buf);
Expand Down Expand Up @@ -722,7 +722,7 @@ vim_findfile(void *search_ctx_arg)
* filepath is used as buffer for various actions and as the storage to
* return a found filename.
*/
if ((file_path = alloc((int)MAXPATHL)) == NULL)
if ((file_path = alloc(MAXPATHL)) == NULL)
return NULL;

#ifdef FEAT_PATH_EXTRA
Expand Down Expand Up @@ -1866,7 +1866,7 @@ find_file_in_path_option(
break;
}

if ((buf = alloc((int)(MAXPATHL))) == NULL)
if ((buf = alloc(MAXPATHL)) == NULL)
break;

// copy next path
Expand Down Expand Up @@ -2274,7 +2274,7 @@ expand_path_option(char_u *curdir, garray_T *gap)
char_u *p;
int len;

if ((buf = alloc((int)MAXPATHL)) == NULL)
if ((buf = alloc(MAXPATHL)) == NULL)
return;

while (*path_option != NUL)
Expand Down Expand Up @@ -2424,7 +2424,7 @@ uniquefy_paths(garray_T *gap, char_u *pattern)
if (regmatch.regprog == NULL)
return;

if ((curdir = alloc((int)(MAXPATHL))) == NULL)
if ((curdir = alloc(MAXPATHL)) == NULL)
goto theend;
mch_dirname(curdir, MAXPATHL);
expand_path_option(curdir, &path_ga);
Expand Down Expand Up @@ -2532,7 +2532,7 @@ uniquefy_paths(garray_T *gap, char_u *pattern)
continue;
}

rel_path = alloc((int)(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2));
rel_path = alloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2);
if (rel_path == NULL)
goto theend;
STRCPY(rel_path, ".");
Expand Down
2 changes: 1 addition & 1 deletion src/if_ole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ CVim::Eval(BSTR expr, BSTR *result)
if (len == 0)
return E_INVALIDARG;

buffer = (char *)alloc((unsigned)len);
buffer = (char *)alloc(len);

if (buffer == NULL)
return E_OUTOFMEMORY;
Expand Down
6 changes: 3 additions & 3 deletions src/if_py_both.h
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,7 @@ FunctionNew(PyTypeObject *subtype, char_u *name, int argc, typval_T *argv,
char_u *np;
size_t len = STRLEN(p) + 1;

if ((np = alloc((int)len + 2)) == NULL)
if ((np = alloc(len + 2)) == NULL)
{
vim_free(p);
return NULL;
Expand Down Expand Up @@ -3139,7 +3139,7 @@ set_partial(FunctionObject *self, partial_T *pt, int exported)
if (exported)
{
pt->pt_argv = (typval_T *)alloc_clear(
sizeof(typval_T) * self->argc);
sizeof(typval_T) * self->argc);
for (i = 0; i < pt->pt_argc; ++i)
copy_tv(&self->argv[i], &pt->pt_argv[i]);
}
Expand Down Expand Up @@ -4262,7 +4262,7 @@ StringToLine(PyObject *obj)
/* Create a copy of the string, with internal nulls replaced by
* newline characters, as is the vim convention.
*/
save = (char *)alloc((unsigned)(len+1));
save = (char *)alloc(len+1);
if (save == NULL)
{
PyErr_NoMemory();
Expand Down
4 changes: 2 additions & 2 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ list_alloc(void)
list_alloc_id(alloc_id_T id UNUSED)
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T)))
if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T)))
return NULL;
#endif
return (list_alloc());
Expand Down Expand Up @@ -122,7 +122,7 @@ rettv_list_alloc(typval_T *rettv)
rettv_list_alloc_id(typval_T *rettv, alloc_id_T id UNUSED)
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T)))
if (alloc_fail_id == id && alloc_does_fail(sizeof(list_T)))
return FAIL;
#endif
return rettv_list_alloc(rettv);
Expand Down
4 changes: 2 additions & 2 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ add_msg_hist(
(void)delete_first_msg();

/* allocate an entry and add the message at the end of the history */
p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist));
p = (struct msg_hist *)alloc(sizeof(struct msg_hist));
if (p != NULL)
{
if (len < 0)
Expand Down Expand Up @@ -2360,7 +2360,7 @@ store_sb_text(

if (s > *sb_str)
{
mp = (msgchunk_T *)alloc((int)(sizeof(msgchunk_T) + (s - *sb_str)));
mp = (msgchunk_T *)alloc(sizeof(msgchunk_T) + (s - *sb_str));
if (mp != NULL)
{
mp->sb_eol = finish;
Expand Down
4 changes: 2 additions & 2 deletions src/misc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3446,7 +3446,7 @@ dos_expandpath(

// Make room for file name. When doing encoding conversion the actual
// length may be quite a bit longer, thus use the maximum possible length.
buf = alloc((int)MAXPATHL);
buf = alloc(MAXPATHL);
if (buf == NULL)
return 0;

Expand Down Expand Up @@ -3690,7 +3690,7 @@ unix_expandpath(
}

/* make room for file name */
buf = alloc((int)STRLEN(path) + BASENAMELEN + 5);
buf = alloc(STRLEN(path) + BASENAMELEN + 5);
if (buf == NULL)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/misc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ vim_strnsave(char_u *string, int len)
{
char_u *p;

p = alloc((size_t)(len + 1));
p = alloc(len + 1);
if (p != NULL)
{
STRNCPY(p, string, len);
Expand Down
2 changes: 1 addition & 1 deletion src/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,7 @@ copy_yank_reg(yankreg_T *reg)
free_yank_all();
*y_current = *curr;
y_current->y_array = (char_u **)lalloc_clear(
(long_u)(sizeof(char_u *) * y_current->y_size), TRUE);
sizeof(char_u *) * y_current->y_size, TRUE);
if (y_current->y_array == NULL)
y_current->y_size = 0;
else
Expand Down
2 changes: 1 addition & 1 deletion src/os_vms.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ mch_getenv(char_u *lognam)
else if ((sbuf = getenv((char *)lognam)))
{
lengte = strlen(sbuf) + 1;
cp = (char_u *)alloc((size_t)lengte);
cp = (char_u *)alloc(lengte);
if (cp)
strcpy((char *)cp, sbuf);
return cp;
Expand Down
2 changes: 1 addition & 1 deletion src/os_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -7117,7 +7117,7 @@ fix_arg_enc(void)
return;

/* Remember the buffer numbers for the arguments. */
fnum_list = (int *)alloc((int)sizeof(int) * GARGCOUNT);
fnum_list = (int *)alloc(sizeof(int) * GARGCOUNT);
if (fnum_list == NULL)
return; /* out of memory */
for (i = 0; i < GARGCOUNT; ++i)
Expand Down
2 changes: 1 addition & 1 deletion src/quickfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ qf_store_title(qf_list_T *qfl, char_u *title)

if (title != NULL)
{
char_u *p = alloc((int)STRLEN(title) + 2);
char_u *p = alloc(STRLEN(title) + 2);

qfl->qf_title = p;
if (p != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/regexp_nfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -4799,7 +4799,7 @@ addstate_here(
emsg(_(e_maxmempat));
return NULL;
}
newl = (nfa_thread_T *)alloc((int)newsize);
newl = (nfa_thread_T *)alloc(newsize);
if (newl == NULL)
return NULL;
l->len = newlen;
Expand Down
13 changes: 5 additions & 8 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,30 +328,27 @@ redraw_asap(int type)

/* Allocate space to save the text displayed in the command line area. */
rows = screen_Rows - cmdline_row;
screenline = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
screenattr = (sattr_T *)lalloc(
(long_u)(rows * cols * sizeof(sattr_T)), FALSE);
screenline = (schar_T *)lalloc(rows * cols * sizeof(schar_T), FALSE);
screenattr = (sattr_T *)lalloc(rows * cols * sizeof(sattr_T), FALSE);
if (screenline == NULL || screenattr == NULL)
ret = 2;
if (enc_utf8)
{
screenlineUC = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
rows * cols * sizeof(u8char_T), FALSE);
if (screenlineUC == NULL)
ret = 2;
for (i = 0; i < p_mco; ++i)
{
screenlineC[i] = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
rows * cols * sizeof(u8char_T), FALSE);
if (screenlineC[i] == NULL)
ret = 2;
}
}
if (enc_dbcs == DBCS_JPNU)
{
screenline2 = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
screenline2 = (schar_T *)lalloc(rows * cols * sizeof(schar_T), FALSE);
if (screenline2 == NULL)
ret = 2;
}
Expand Down

0 comments on commit 51e1438

Please sign in to comment.