[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: src/usr.bin/window cleanup
- To: bugs_(_at_)_openbsd_(_dot_)_org
- Subject: Re: src/usr.bin/window cleanup
- From: Jared Yanovich <jjy2+_(_at_)_pitt_(_dot_)_edu>
- Date: Mon, 24 Nov 2003 15:37:14 -0500
On Thu, 20 Nov 2003 12:19:11 -0500
Jared Yanovich <jjy2+_(_at_)_pitt_(_dot_)_edu> wrote:
> Changes include allocation checking, slightly more correct variable-
> argument functions, and a little ANSI-fication.
Here is a revised version after some comments from Otto Moerbeek.
- Jared
Index: cmd7.c
===================================================================
RCS file: /cvs/src/usr.bin/window/cmd7.c,v
retrieving revision 1.6
diff -u -r1.6 cmd7.c
--- cmd7.c 2003/07/18 23:11:43 1.6
+++ cmd7.c 2003/11/24 19:34:08
@@ -256,7 +256,10 @@
yp->length = n = cend - c + 1;
if (nl)
yp->length++;
- yp->line = str_alloc(yp->length + 1);
+ if ((yp->line = str_alloc(yp->length + 1)) == NULL) {
+ free(yp);
+ return;
+ }
for (bp += c, cp = yp->line; --n >= 0;)
*cp++ = bp++->c_c;
if (nl)
Index: compress.c
===================================================================
RCS file: /cvs/src/usr.bin/window/compress.c,v
retrieving revision 1.7
diff -u -r1.7 compress.c
--- compress.c 2003/07/10 00:06:52 1.7
+++ compress.c 2003/11/24 19:34:09
@@ -299,8 +299,8 @@
tt_obe = tt_ob + cc_bufsize;
tt.tt_flush = ccflush;
if (cc_trace) {
- cc_trace_fp = fopen("window-trace", "a");
- (void) fcntl(fileno(cc_trace_fp), F_SETFD, 1);
+ if ((cc_trace_fp = fopen("window-trace", "a")) != NULL)
+ (void) fcntl(fileno(cc_trace_fp), F_SETFD, FD_CLOEXEC);
}
ccreset();
}
Index: error.c
===================================================================
RCS file: /cvs/src/usr.bin/window/error.c,v
retrieving revision 1.6
diff -u -r1.6 error.c
--- error.c 2003/06/03 02:56:23 1.6
+++ error.c 2003/11/24 19:34:09
@@ -46,11 +46,12 @@
#include "context.h"
#include "char.h"
+#include <stdarg.h>
+
#define ERRLINES 10 /* number of lines for errwin */
-/*VARARGS1*/
-error(fmt, a, b, c, d, e, f, g, h)
-char *fmt;
+void
+verror(char *fmt, va_list ap)
{
struct context *x;
struct ww *w;
@@ -61,7 +62,7 @@
if (terse)
wwbell();
else {
- wwprintf(cmdwin, fmt, a, b, c, d, e, f, g, h);
+ wwvprintf(cmdwin, fmt, ap);
wwputs(" ", cmdwin);
}
return;
@@ -83,8 +84,19 @@
return;
}
wwprintf(w, "line %d: ", x->x_lineno);
- wwprintf(w, fmt, a, b, c, d, e, f, g, h);
+ wwvprintf(w, fmt, ap);
wwputc('\n', w);
+}
+
+/*VARARGS1*/
+void
+error(char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ verror(fmt, ap);
+ va_end(ap);
}
err_end()
Index: parser.h
===================================================================
RCS file: /cvs/src/usr.bin/window/parser.h,v
retrieving revision 1.4
diff -u -r1.4 parser.h
--- parser.h 2003/06/03 02:56:23 1.4
+++ parser.h 2003/11/24 19:34:09
@@ -44,3 +44,5 @@
#define p_synerred() (cx.x_synerred)
#define p_clearerr() (cx.x_erred = cx.x_synerred = 0)
#define p_abort() (cx.x_abort)
+
+void p_error(char *msg, ...);
Index: parser1.c
===================================================================
RCS file: /cvs/src/usr.bin/window/parser1.c,v
retrieving revision 1.5
diff -u -r1.5 parser1.c
--- parser1.c 2003/06/03 02:56:23 1.5
+++ parser1.c 2003/11/24 19:34:10
@@ -43,6 +43,8 @@
#include "parser.h"
+#include <stdarg.h>
+
p_start()
{
char flag = 1;
@@ -209,12 +211,15 @@
}
/*VARARGS1*/
-p_error(msg, a, b, c)
-char *msg;
+void p_error(char *msg, ...)
{
+ va_list ap;
+
if (!cx.x_erred) {
cx.x_erred = 1;
- error(msg, a, b, c);
+ va_start(ap, msg);
+ verror(msg, ap);
+ va_end(ap);
}
}
Index: ttinit.c
===================================================================
RCS file: /cvs/src/usr.bin/window/ttinit.c,v
retrieving revision 1.10
diff -u -r1.10 ttinit.c
--- ttinit.c 2003/06/03 02:56:23 1.10
+++ ttinit.c 2003/11/24 19:34:10
@@ -94,7 +94,10 @@
* non-two letter name in termcap).
*/
#ifdef NCURSES_VERSION
- wwterm = strdup(_nc_first_name(cur_term->type.term_names));
+ if ((wwterm = strdup(_nc_first_name(cur_term->type.term_names))) == NULL) {
+ wwerrno = WWE_NOMEM;
+ return -1;
+ }
#elif !defined(TERMINFO)
if ((p = strchr(wwtermcap, '|')) && (int)(p - wwtermcap) == 2) {
/* Skip the two-character short name. */
Index: wwprintf.c
===================================================================
RCS file: /cvs/src/usr.bin/window/wwprintf.c,v
retrieving revision 1.7
diff -u -r1.7 wwprintf.c
--- wwprintf.c 2003/08/01 22:01:37 1.7
+++ wwprintf.c 2003/11/24 19:34:10
@@ -45,13 +45,21 @@
#include <stdarg.h>
#include <stdio.h>
-wwprintf(struct ww *w, char *fmt, ...)
+void
+wwvprintf(struct ww *w, char *fmt, va_list ap)
{
char buf[1024];
+
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ (void) wwwrite(w, buf, strlen(buf));
+}
+
+void
+wwprintf(struct ww *w, char *fmt, ...)
+{
va_list ap;
va_start(ap, fmt);
- /* buffer can overflow */
- (void) wwwrite(w, buf, vsnprintf(buf, sizeof(buf), fmt, ap));
+ wwvprintf(w, fmt, ap);
va_end(ap);
}
Visit your host, monkey.org