1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-04 19:40:41 +00:00

Fix potential buffer overflow and align failure message display method on exit.

This commit is contained in:
Renaud 2015-03-23 19:12:38 +08:00
parent 66649313ae
commit f8eb3531a4

29
tcap.c
View File

@ -126,22 +126,21 @@ static void tcapopen(void)
char *t, *p; char *t, *p;
char tcbuf[1024]; char tcbuf[1024];
char *tv_stype; char *tv_stype;
char err_str[72];
int int_col, int_row; int int_col, int_row;
#if PKCODE && USE_BROKEN_OPTIMIZATION #if PKCODE && USE_BROKEN_OPTIMIZATION
if (!term_init_ok) { if (!term_init_ok) {
#endif #endif
if ((tv_stype = getenv("TERM")) == NULL) { if ((tv_stype = getenv("TERM")) == NULL) {
puts("Environment variable TERM not defined!"); fputs( "Environment variable TERM not defined!\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
if ((tgetent(tcbuf, tv_stype)) != 1) { if ((tgetent(tcbuf, tv_stype)) != 1) {
sprintf(err_str, "Unknown terminal type %s!", fputs( "Unknown terminal type ", stderr) ;
tv_stype); fputs( tv_stype, stderr) ;
puts(err_str); fputs( "!\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
/* Get screen size from system, or else from termcap. */ /* Get screen size from system, or else from termcap. */
@ -151,14 +150,14 @@ static void tcapopen(void)
if ((term.t_nrow <= 0) if ((term.t_nrow <= 0)
&& (term.t_nrow = (short) tgetnum("li") - 1) == -1) { && (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
puts("termcap entry incomplete (lines)"); fputs( "termcap entry incomplete (lines)\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
if ((term.t_ncol <= 0) if ((term.t_ncol <= 0)
&& (term.t_ncol = (short) tgetnum("co")) == -1) { && (term.t_ncol = (short) tgetnum("co")) == -1) {
puts("Termcap entry incomplete (columns)"); fputs( "Termcap entry incomplete (columns)\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
#ifdef SIGWINCH #ifdef SIGWINCH
/* At initialization we use maximum size even if current OS window is smaller */ /* At initialization we use maximum size even if current OS window is smaller */
@ -199,8 +198,8 @@ static void tcapopen(void)
#endif #endif
if (CL == NULL || CM == NULL || UP == NULL) { if (CL == NULL || CM == NULL || UP == NULL) {
puts("Incomplete termcap entry\n"); fputs( "Incomplete termcap entry\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
if (CE == NULL) /* will we be able to use clear to EOL? */ if (CE == NULL) /* will we be able to use clear to EOL? */
@ -224,8 +223,8 @@ static void tcapopen(void)
#endif #endif
if (p >= &tcapbuf[TCAPSLEN]) { if (p >= &tcapbuf[TCAPSLEN]) {
puts("Terminal description too big!\n"); fputs( "Terminal description too big!\n", stderr) ;
exit(1); exit( EXIT_FAILURE) ;
} }
#if PKCODE && USE_BROKEN_OPTIMIZATION #if PKCODE && USE_BROKEN_OPTIMIZATION
term_init_ok = 1; term_init_ok = 1;