No OOM error condition in prep_exarg()

This commit is contained in:
Felipe Oliveira Carvalho 2014-04-19 01:56:26 -03:00 committed by Thiago de Arruda
parent 15d8f702a8
commit 4b6b9117b3
3 changed files with 109 additions and 118 deletions

View File

@ -4659,10 +4659,7 @@ int buf_contents_changed(buf_T *buf)
return TRUE; return TRUE;
/* Force the 'fileencoding' and 'fileformat' to be equal. */ /* Force the 'fileencoding' and 'fileformat' to be equal. */
if (prep_exarg(&ea, buf) == FAIL) { prep_exarg(&ea, buf);
wipe_buffer(newbuf, FALSE);
return TRUE;
}
/* set curwin/curbuf to buf and save a few things */ /* set curwin/curbuf to buf and save a few things */
aucmd_prepbuf(&aco, newbuf); aucmd_prepbuf(&aco, newbuf);

View File

@ -2062,15 +2062,10 @@ readfile_linenr (
/* /*
* Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be * Fill "*eap" to force the 'fileencoding', 'fileformat' and 'binary to be
* equal to the buffer "buf". Used for calling readfile(). * equal to the buffer "buf". Used for calling readfile().
* Returns OK or FAIL.
*/ */
int prep_exarg(exarg_T *eap, buf_T *buf) void prep_exarg(exarg_T *eap, buf_T *buf)
{ {
eap->cmd = alloc((unsigned)(STRLEN(buf->b_p_ff) eap->cmd = xmalloc(STRLEN(buf->b_p_ff) + STRLEN(buf->b_p_fenc) + 15);
+ STRLEN(buf->b_p_fenc)
+ 15));
if (eap->cmd == NULL)
return FAIL;
sprintf((char *)eap->cmd, "e ++ff=%s ++enc=%s", buf->b_p_ff, buf->b_p_fenc); sprintf((char *)eap->cmd, "e ++ff=%s ++enc=%s", buf->b_p_ff, buf->b_p_fenc);
eap->force_enc = 14 + (int)STRLEN(buf->b_p_ff); eap->force_enc = 14 + (int)STRLEN(buf->b_p_ff);
@ -2080,7 +2075,6 @@ int prep_exarg(exarg_T *eap, buf_T *buf)
eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN; eap->force_bin = buf->b_p_bin ? FORCE_BIN : FORCE_NOBIN;
eap->read_edit = FALSE; eap->read_edit = FALSE;
eap->forceit = FALSE; eap->forceit = FALSE;
return OK;
} }
/* /*
@ -5456,10 +5450,11 @@ void buf_reload(buf_T *buf, int orig_mode)
/* set curwin/curbuf for "buf" and save some things */ /* set curwin/curbuf for "buf" and save some things */
aucmd_prepbuf(&aco, buf); aucmd_prepbuf(&aco, buf);
/* We only want to read the text from the file, not reset the syntax // We only want to read the text from the file, not reset the syntax
* highlighting, clear marks, diff status, etc. Force the fileformat // highlighting, clear marks, diff status, etc. Force the fileformat and
* and encoding to be the same. */ // encoding to be the same.
if (prep_exarg(&ea, buf) == OK) {
prep_exarg(&ea, buf);
old_cursor = curwin->w_cursor; old_cursor = curwin->w_cursor;
old_topline = curwin->w_topline; old_topline = curwin->w_topline;
@ -5563,7 +5558,6 @@ void buf_reload(buf_T *buf, int orig_mode)
/* Modelines must override settings done by autocommands. */ /* Modelines must override settings done by autocommands. */
do_modelines(0); do_modelines(0);
}
/* restore curwin/curbuf and a few other things */ /* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco); aucmd_restbuf(&aco);

View File

@ -21,7 +21,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr);
int readfile(char_u *fname, char_u *sfname, linenr_T from, int readfile(char_u *fname, char_u *sfname, linenr_T from,
linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap,
int flags); int flags);
int prep_exarg(exarg_T *eap, buf_T *buf); void prep_exarg(exarg_T *eap, buf_T *buf);
void set_file_options(int set_options, exarg_T *eap); void set_file_options(int set_options, exarg_T *eap);
void set_forced_fenc(exarg_T *eap); void set_forced_fenc(exarg_T *eap);
int prepare_crypt_read(FILE *fp); int prepare_crypt_read(FILE *fp);