Skip to content

Commit

Permalink
patch 9.0.1246: code is indented more than necessary
Browse files Browse the repository at this point in the history
Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11887)
  • Loading branch information
yegappan authored and brammool committed Jan 26, 2023
1 parent 032713f commit 142ed77
Show file tree
Hide file tree
Showing 13 changed files with 505 additions and 510 deletions.
54 changes: 27 additions & 27 deletions src/ui.c
Expand Up @@ -83,20 +83,20 @@ ui_inchar_undo(char_u *s, int len)
if (ta_str != NULL)
newlen += ta_len - ta_off;
new = alloc(newlen);
if (new != NULL)
if (new == NULL)
return;

if (ta_str != NULL)
{
if (ta_str != NULL)
{
mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
mch_memmove(new + ta_len - ta_off, s, (size_t)len);
vim_free(ta_str);
}
else
mch_memmove(new, s, (size_t)len);
ta_str = new;
ta_len = newlen;
ta_off = 0;
mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off));
mch_memmove(new + ta_len - ta_off, s, (size_t)len);
vim_free(ta_str);
}
else
mch_memmove(new, s, (size_t)len);
ta_str = new;
ta_len = newlen;
ta_off = 0;
}
#endif

Expand Down Expand Up @@ -815,25 +815,25 @@ set_input_buf(char_u *p, int overwrite)
{
garray_T *gap = (garray_T *)p;

if (gap != NULL)
if (gap == NULL)
return;

if (gap->ga_data != NULL)
{
if (gap->ga_data != NULL)
if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
{
if (overwrite || inbufcount + gap->ga_len >= INBUFLEN)
{
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
inbufcount = gap->ga_len;
}
else
{
mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
inbufcount += gap->ga_len;
}
vim_free(gap->ga_data);
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
inbufcount = gap->ga_len;
}
else
{
mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount);
mch_memmove(inbuf, gap->ga_data, gap->ga_len);
inbufcount += gap->ga_len;
}
vim_free(gap);
vim_free(gap->ga_data);
}
vim_free(gap);
}

/*
Expand Down
68 changes: 34 additions & 34 deletions src/undo.c
Expand Up @@ -1164,21 +1164,21 @@ read_string_decrypt(bufinfo_T *bi, int len)
{
char_u *ptr = alloc(len + 1);

if (ptr != NULL)
if (ptr == NULL)
return NULL;

if (len > 0 && undo_read(bi, ptr, len) == FAIL)
{
if (len > 0 && undo_read(bi, ptr, len) == FAIL)
{
vim_free(ptr);
return NULL;
}
// In case there are text properties there already is a NUL, but
// checking for that is more expensive than just adding a dummy byte.
ptr[len] = NUL;
vim_free(ptr);
return NULL;
}
// In case there are text properties there already is a NUL, but
// checking for that is more expensive than just adding a dummy byte.
ptr[len] = NUL;
#ifdef FEAT_CRYPT
if (bi->bi_state != NULL && bi->bi_buffer == NULL)
crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
if (bi->bi_state != NULL && bi->bi_buffer == NULL)
crypt_decode_inplace(bi->bi_state, ptr, len, FALSE);
#endif
}
return ptr;
}

Expand Down Expand Up @@ -3510,12 +3510,12 @@ u_saveline(linenr_T lnum)
void
u_clearline(void)
{
if (curbuf->b_u_line_ptr.ul_line != NULL)
{
VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
curbuf->b_u_line_ptr.ul_len = 0;
curbuf->b_u_line_lnum = 0;
}
if (curbuf->b_u_line_ptr.ul_line == NULL)
return;

VIM_CLEAR(curbuf->b_u_line_ptr.ul_line);
curbuf->b_u_line_ptr.ul_len = 0;
curbuf->b_u_line_lnum = 0;
}

/*
Expand Down Expand Up @@ -3726,24 +3726,24 @@ u_undofile_reset_and_delete(buf_T *buf)
void
f_undotree(typval_T *argvars UNUSED, typval_T *rettv)
{
if (rettv_dict_alloc(rettv) == OK)
{
dict_T *dict = rettv->vval.v_dict;
list_T *list;
if (rettv_dict_alloc(rettv) == FAIL)
return;

dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);
dict_T *dict = rettv->vval.v_dict;
list_T *list;

list = list_alloc();
if (list != NULL)
{
u_eval_tree(curbuf->b_u_oldhead, list);
dict_add_list(dict, "entries", list);
}
dict_add_number(dict, "synced", (long)curbuf->b_u_synced);
dict_add_number(dict, "seq_last", curbuf->b_u_seq_last);
dict_add_number(dict, "save_last", curbuf->b_u_save_nr_last);
dict_add_number(dict, "seq_cur", curbuf->b_u_seq_cur);
dict_add_number(dict, "time_cur", (long)curbuf->b_u_time_cur);
dict_add_number(dict, "save_cur", curbuf->b_u_save_nr_cur);

list = list_alloc();
if (list != NULL)
{
u_eval_tree(curbuf->b_u_oldhead, list);
dict_add_list(dict, "entries", list);
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/uninstall.c
Expand Up @@ -205,18 +205,18 @@ batfile_thisversion(char *path)
int found = FALSE;

fd = fopen(path, "r");
if (fd != NULL)
if (fd == NULL)
return FALSE;

while (fgets(line, sizeof(line), fd) != NULL)
{
while (fgets(line, sizeof(line), fd) != NULL)
if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
{
if (strncmp(line, VIMBAT_UNINSTKEY, key_len) == 0)
{
found = TRUE;
break;
}
found = TRUE;
break;
}
fclose(fd);
}
fclose(fd);
return found;
}

Expand Down Expand Up @@ -261,12 +261,12 @@ remove_if_exists(char *path, char *filename)
sprintf(buf, "%s\\%s", path, filename);

fd = fopen(buf, "r");
if (fd != NULL)
{
fclose(fd);
printf("removing %s\n", buf);
remove(buf);
}
if (fd == NULL)
return;

fclose(fd);
printf("removing %s\n", buf);
remove(buf);
}

static void
Expand All @@ -287,21 +287,21 @@ remove_start_menu(void)
int i;
struct stat st;

if (get_shell_folder_path(path, VIM_STARTMENU))
if (get_shell_folder_path(path, VIM_STARTMENU) == FAIL)
return;

for (i = 1; i < TARGET_COUNT; ++i)
remove_if_exists(path, targets[i].lnkname);
remove_if_exists(path, "uninstall.lnk");
remove_if_exists(path, "Help.lnk");
// Win95 uses .pif, WinNT uses .lnk
remove_if_exists(path, "Vim tutor.pif");
remove_if_exists(path, "Vim tutor.lnk");
remove_if_exists(path, "Vim online.url");
if (stat(path, &st) == 0)
{
for (i = 1; i < TARGET_COUNT; ++i)
remove_if_exists(path, targets[i].lnkname);
remove_if_exists(path, "uninstall.lnk");
remove_if_exists(path, "Help.lnk");
// Win95 uses .pif, WinNT uses .lnk
remove_if_exists(path, "Vim tutor.pif");
remove_if_exists(path, "Vim tutor.lnk");
remove_if_exists(path, "Vim online.url");
if (stat(path, &st) == 0)
{
printf("removing %s\n", path);
rmdir(path);
}
printf("removing %s\n", path);
rmdir(path);
}
}

Expand Down
57 changes: 28 additions & 29 deletions src/userfunc.c
Expand Up @@ -770,25 +770,25 @@ is_function_cmd(char_u **cmd)
static void
function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
{
if (cstack != NULL && cstack->cs_idx >= 0)
{
int count = cstack->cs_idx + 1;
int i;
if (cstack == NULL || cstack->cs_idx < 0)
return;

fp->uf_block_ids = ALLOC_MULT(int, count);
if (fp->uf_block_ids != NULL)
{
mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
sizeof(int) * count);
fp->uf_block_depth = count;
}
int count = cstack->cs_idx + 1;
int i;

// Set flag in each block to indicate a function was defined. This
// is used to keep the variable when leaving the block, see
// hide_script_var().
for (i = 0; i <= cstack->cs_idx; ++i)
cstack->cs_flags[i] |= CSF_FUNC_DEF;
fp->uf_block_ids = ALLOC_MULT(int, count);
if (fp->uf_block_ids != NULL)
{
mch_memmove(fp->uf_block_ids, cstack->cs_block_id,
sizeof(int) * count);
fp->uf_block_depth = count;
}

// Set flag in each block to indicate a function was defined. This
// is used to keep the variable when leaving the block, see
// hide_script_var().
for (i = 0; i <= cstack->cs_idx; ++i)
cstack->cs_flags[i] |= CSF_FUNC_DEF;
}

/*
Expand Down Expand Up @@ -2433,21 +2433,20 @@ func_remove(ufunc_T *fp)
return FALSE;

hi = hash_find(&func_hashtab, UF2HIKEY(fp));
if (!HASHITEM_EMPTY(hi))
if (HASHITEM_EMPTY(hi))
return FALSE;

// When there is a def-function index do not actually remove the
// function, so we can find the index when defining the function again.
// Do remove it when it's a copy.
if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
{
// When there is a def-function index do not actually remove the
// function, so we can find the index when defining the function again.
// Do remove it when it's a copy.
if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0)
{
fp->uf_flags |= FC_DEAD;
return FALSE;
}
hash_remove(&func_hashtab, hi, "remove function");
fp->uf_flags |= FC_DELETED;
return TRUE;
fp->uf_flags |= FC_DEAD;
return FALSE;
}
return FALSE;
hash_remove(&func_hashtab, hi, "remove function");
fp->uf_flags |= FC_DELETED;
return TRUE;
}

static void
Expand Down
34 changes: 18 additions & 16 deletions src/version.c
Expand Up @@ -57,26 +57,26 @@ char *longVersion = NULL;
void
init_longVersion(void)
{
if (longVersion == NULL)
{
if (longVersion != NULL)
return;

#ifdef BUILD_DATE
char *date_time = BUILD_DATE;
char *date_time = BUILD_DATE;
#else
char *date_time = __DATE__ " " __TIME__;
char *date_time = __DATE__ " " __TIME__;
#endif
char *msg = _("%s (%s, compiled %s)");
size_t len = strlen(msg)
+ strlen(VIM_VERSION_LONG_ONLY)
+ strlen(VIM_VERSION_DATE_ONLY)
+ strlen(date_time);
char *msg = _("%s (%s, compiled %s)");
size_t len = strlen(msg)
+ strlen(VIM_VERSION_LONG_ONLY)
+ strlen(VIM_VERSION_DATE_ONLY)
+ strlen(date_time);

longVersion = alloc(len);
if (longVersion == NULL)
longVersion = VIM_VERSION_LONG;
else
vim_snprintf(longVersion, len, msg,
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
}
longVersion = alloc(len);
if (longVersion == NULL)
longVersion = VIM_VERSION_LONG;
else
vim_snprintf(longVersion, len, msg,
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
}
# endif
#else
Expand Down Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1246,
/**/
1245,
/**/
Expand Down

0 comments on commit 142ed77

Please sign in to comment.