Remove OOM checks: realloc_cmdbuff()

put_on_cmdline() doesn't FAIL anymore but its return value was
never checked.
This commit is contained in:
Felipe Oliveira Carvalho 2014-05-10 01:00:14 -03:00
parent eb636858b5
commit 27f5f7b1e8
2 changed files with 130 additions and 141 deletions

View File

@ -118,7 +118,7 @@ static void set_cmdspos(void);
static void set_cmdspos_cursor(void); static void set_cmdspos_cursor(void);
static void correct_cmdspos(int idx, int cells); static void correct_cmdspos(int idx, int cells);
static void alloc_cmdbuff(int len); static void alloc_cmdbuff(int len);
static int realloc_cmdbuff(int len); static void realloc_cmdbuff(int len);
static void draw_cmdline(int start, int len); static void draw_cmdline(int start, int len);
static void save_cmdline(struct cmdline_info *ccp); static void save_cmdline(struct cmdline_info *ccp);
static void restore_cmdline(struct cmdline_info *ccp); static void restore_cmdline(struct cmdline_info *ccp);
@ -614,7 +614,7 @@ getcmdline (
if (p != NULL) { if (p != NULL) {
len = (int)STRLEN(p); len = (int)STRLEN(p);
if (realloc_cmdbuff(len + 1) == OK) { realloc_cmdbuff(len + 1);
ccline.cmdlen = len; ccline.cmdlen = len;
STRCPY(ccline.cmdbuff, p); STRCPY(ccline.cmdbuff, p);
free(p); free(p);
@ -631,7 +631,6 @@ getcmdline (
goto cmdline_changed; goto cmdline_changed;
} }
} }
}
beep_flush(); beep_flush();
got_int = FALSE; /* don't abandon the command line */ got_int = FALSE; /* don't abandon the command line */
did_emsg = FALSE; did_emsg = FALSE;
@ -1994,14 +1993,13 @@ static void alloc_cmdbuff(int len)
/* /*
* Re-allocate the command line to length len + something extra. * Re-allocate the command line to length len + something extra.
*/ */
static int realloc_cmdbuff(int len) static void realloc_cmdbuff(int len)
{ {
char_u *p; if (len < ccline.cmdbufflen) {
return; // no need to resize
}
if (len < ccline.cmdbufflen) char_u *p = ccline.cmdbuff;
return OK; /* no need to resize */
p = ccline.cmdbuff;
alloc_cmdbuff(len); /* will get some more */ alloc_cmdbuff(len); /* will get some more */
/* There isn't always a NUL after the command, but it may need to be /* There isn't always a NUL after the command, but it may need to be
* there, thus copy up to the NUL and add a NUL. */ * there, thus copy up to the NUL and add a NUL. */
@ -2020,8 +2018,6 @@ static int realloc_cmdbuff(int len)
if (i >= 0 && i <= ccline.cmdlen) if (i >= 0 && i <= ccline.cmdlen)
ccline.xpc->xp_pattern = ccline.cmdbuff + i; ccline.xpc->xp_pattern = ccline.cmdbuff + i;
} }
return OK;
} }
static char_u *arshape_buf = NULL; static char_u *arshape_buf = NULL;
@ -2174,9 +2170,8 @@ void unputcmdline(void)
* twice in a row, then 'redraw' should be FALSE and redrawcmd() should be * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be
* called afterwards. * called afterwards.
*/ */
int put_on_cmdline(char_u *str, int len, int redraw) void put_on_cmdline(char_u *str, int len, int redraw)
{ {
int retval;
int i; int i;
int m; int m;
int c; int c;
@ -2185,11 +2180,10 @@ int put_on_cmdline(char_u *str, int len, int redraw)
len = (int)STRLEN(str); len = (int)STRLEN(str);
/* Check if ccline.cmdbuff needs to be longer */ /* Check if ccline.cmdbuff needs to be longer */
if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) {
retval = realloc_cmdbuff(ccline.cmdlen + len + 1); realloc_cmdbuff(ccline.cmdlen + len + 1);
else }
retval = OK;
if (retval == OK) {
if (!ccline.overstrike) { if (!ccline.overstrike) {
memmove(ccline.cmdbuff + ccline.cmdpos + len, memmove(ccline.cmdbuff + ccline.cmdpos + len,
ccline.cmdbuff + ccline.cmdpos, ccline.cmdbuff + ccline.cmdpos,
@ -2295,10 +2289,9 @@ int put_on_cmdline(char_u *str, int len, int redraw)
++ccline.cmdpos; ++ccline.cmdpos;
} }
} }
}
if (redraw) if (redraw)
msg_check(); msg_check();
return retval;
} }
static struct cmdline_info prev_ccline; static struct cmdline_info prev_ccline;
@ -2631,7 +2624,6 @@ nextwild (
char_u *p1; char_u *p1;
char_u *p2; char_u *p2;
int difflen; int difflen;
int v;
if (xp->xp_numfiles == -1) { if (xp->xp_numfiles == -1) {
set_expand_context(xp); set_expand_context(xp);
@ -2694,11 +2686,9 @@ nextwild (
if (p2 != NULL && !got_int) { if (p2 != NULL && !got_int) {
difflen = (int)STRLEN(p2) - xp->xp_pattern_len; difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) { if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) {
v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); realloc_cmdbuff(ccline.cmdlen + difflen + 4);
xp->xp_pattern = ccline.cmdbuff + i; xp->xp_pattern = ccline.cmdbuff + i;
} else }
v = OK;
if (v == OK) {
memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], memmove(&ccline.cmdbuff[ccline.cmdpos + difflen],
&ccline.cmdbuff[ccline.cmdpos], &ccline.cmdbuff[ccline.cmdpos],
(size_t)(ccline.cmdlen - ccline.cmdpos + 1)); (size_t)(ccline.cmdlen - ccline.cmdpos + 1));
@ -2706,7 +2696,6 @@ nextwild (
ccline.cmdlen += difflen; ccline.cmdlen += difflen;
ccline.cmdpos += difflen; ccline.cmdpos += difflen;
} }
}
free(p2); free(p2);
redrawcmd(); redrawcmd();

View File

@ -14,7 +14,7 @@ char_u *getexmodeline(int promptc, void *cookie, int indent);
void free_cmdline_buf(void); void free_cmdline_buf(void);
void putcmdline(int c, int shift); void putcmdline(int c, int shift);
void unputcmdline(void); void unputcmdline(void);
int put_on_cmdline(char_u *str, int len, int redraw); void put_on_cmdline(char_u *str, int len, int redraw);
char_u *save_cmdline_alloc(void); char_u *save_cmdline_alloc(void);
void restore_cmdline_alloc(char_u *p); void restore_cmdline_alloc(char_u *p);
void cmdline_paste_str(char_u *s, int literally); void cmdline_paste_str(char_u *s, int literally);