Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jul 2001 22:17:24 -0400 (EDT)
From:      Mike Barcroft <mike@q9media.com>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        audit@FreeBSD.org
Subject:   Re: src/bin/ed patch
Message-ID:  <200107030217.f632HOT06228@coffee.q9media.com>

next in thread | raw e-mail | index | archive | help
Bruce Evans <bde@zeta.org.au> writes:
> > Why not just add a switch in /etc/{defaults/,}make.conf to allow one
> > to control the visibility of RCSIDs?  What concern is it of ours if the
> > other BSDs embed RCSIDs unconditionally?
>
> It would be silly to have a switch to fully control FreeBSD rcsids if
> OtherBSD rcsids get embedded (in object files) unconditionally.

Maybe it's not a simple as I think it is.  Would we not just wrap the
__RCSID macros in <sys/cdefs.h> with #ifndef NO_RCSIDS ?  Are there
other requirements I'm not aware of?  If this is all that's required
we should be able to patch our tree and send diffs off to OtherBSD.

> Why change the original copyright string (source and oupput format)?
> The copyright normally goes in a separate "#ifdef lint".

Fixed.  Fixed.

> > ...
> > @@ -1385,12 +1377,13 @@
> >  {
> >       char *hup = NULL;               /* hup filename */
> >       char *s;
> > +     char ed_hup[] = "ed.hup";
> >       int n;
> >  
> >       if (!sigactive)
> >               quit(1);
> >       sigflags &= ~(1 << (signo - 1));
> > -     if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
> > +     if (addr_last && write_file(ed_hup, "w", 1, addr_last) < 0 &&
> >           (s = getenv("HOME")) != NULL &&
> >           (n = strlen(s)) + 8 <= PATH_MAX &&  /* "ed.hup" + '/' */
> >           (hup = (char *) malloc(n + 10)) != NULL) {
>
> The correct fix is to declare write_file()'s first arg as const.

The write_file() routine calls strip_escapes(), which needs to modify
the filename before fopen()ing it.  I'm not sure how it worked
originally as a const.  Probably because it doesn't have any escapes
that it needs to strip.

> BTW, I think we're only seeing the tip of the iceberg for constant
> poisoning of function args.  -Wwrite-strings triggers a few warnings
> for "char *" args, but there are zillions of interfaces that take
> pointers to data that is not changed by the interface yet not declared
> const.  Change a top-level interface to declare things as const and
> the poison will spread to lower levels.

I did a little investigation and the code is a nightmare.  It makes
all kinds of assumptions that don't work in a const-capable world.  I
added a few more consts where it was possible without re-writing all
the callers.

While I was there, I corrected some other small things that were
bugging my eyes (specificly: sprintf and register).

An updated version of my patch is available at the end of this message
and also at: http://testbed.q9media.net/freebsd/ed.20010702.patch

Best regards,
Mike Barcroft

-----------------------------------------------------------------------

ed.20010702.patch

o Correctly define rcsid [requested by bde].
o Add consts where appropriate.
o Rename some variables that are shadowing global declarations.
o Remove register storage-classes.
o sprintf -> snprintf
o Set WARNS?=2


Index: ed/Makefile
===================================================================
RCS file: /home/ncvs/src/bin/ed/Makefile,v
retrieving revision 1.18
diff -u -r1.18 Makefile
--- ed/Makefile	2000/02/29 11:39:24	1.18
+++ ed/Makefile	2001/07/03 01:32:26
@@ -1,6 +1,7 @@
 # $FreeBSD: src/bin/ed/Makefile,v 1.18 2000/02/29 11:39:24 markm Exp $
 
 PROG=	ed
+WARNS?=	2
 SRCS=	buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
 LINKS=	${BINDIR}/ed ${BINDIR}/red
 MLINKS=	ed.1 red.1
Index: ed/buf.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/buf.c,v
retrieving revision 1.17
diff -u -r1.17 buf.c
--- ed/buf.c	1999/08/27 23:14:12	1.17
+++ ed/buf.c	2001/07/03 01:32:26
@@ -27,12 +27,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] = 
   "$FreeBSD: src/bin/ed/buf.c,v 1.17 1999/08/27 23:14:12 peter Exp $";
-#endif
 #endif /* not lint */
 
 #include <sys/file.h>
@@ -65,7 +61,8 @@
 		sfseek = lp->seek;
 		if (fseek(sfp, sfseek, SEEK_SET) < 0) {
 			fprintf(stderr, "%s\n", strerror(errno));
-			sprintf(errmsg, "cannot seek temp file");
+			snprintf(errmsg, sizeof(errmsg),
+			    "cannot seek temp file");
 			return NULL;
 		}
 	}
@@ -73,7 +70,7 @@
 	REALLOC(sfbuf, sfbufsz, len + 1, NULL);
 	if ((ct = fread(sfbuf, sizeof(char), len, sfp)) <  0 || ct != len) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "cannot read temp file");
+		snprintf(errmsg, sizeof(errmsg), "cannot read temp file");
 		return NULL;
 	}
 	sfseek += len;				/* update file position */
@@ -84,24 +81,24 @@
 
 /* put_sbuf_line: write a line of text to the scratch file and add a line node
    to the editor buffer;  return a pointer to the end of the text */
-char *
+const char *
 put_sbuf_line(cs)
-	char *cs;
+	const char *cs;
 {
 	line_t *lp;
 	int len, ct;
-	char *s;
+	const char *s;
 
 	if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "out of memory");
+		snprintf(errmsg, sizeof(errmsg), "out of memory");
 		return NULL;
 	}
 	/* assert: cs is '\n' terminated */
 	for (s = cs; *s != '\n'; s++)
 		;
 	if (s - cs >= LINECHARS) {
-		sprintf(errmsg, "line too long");
+		snprintf(errmsg, sizeof(errmsg), "line too long");
 		return NULL;
 	}
 	len = s - cs;
@@ -109,7 +106,8 @@
 	if (seek_write) {
 		if (fseek(sfp, 0L, SEEK_END) < 0) {
 			fprintf(stderr, "%s\n", strerror(errno));
-			sprintf(errmsg, "cannot seek temp file");
+			snprintf(errmsg, sizeof(errmsg),
+			    "cannot seek temp file");
 			return NULL;
 		}
 		sfseek = ftell(sfp);
@@ -119,7 +117,7 @@
 	if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
 		sfseek = -1;
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "cannot write temp file");
+		snprintf(errmsg, sizeof(errmsg), "cannot write temp file");
 		return NULL;
 	}
 	lp->len = len;
@@ -155,7 +153,7 @@
 	while (cp != lp && (cp = cp->q_forw) != &buffer_head)
 		n++;
 	if (n && cp == &buffer_head) {
-		sprintf(errmsg, "invalid address");
+		snprintf(errmsg, sizeof(errmsg), "invalid address");
 		return ERR;
 	 }
 	 return n;
@@ -229,7 +227,8 @@
 	if (sfp) {
 		if (fclose(sfp) < 0) {
 			fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
-			sprintf(errmsg, "cannot close temp file");
+			snprintf(errmsg, sizeof(errmsg),
+			    "cannot close temp file");
 			return ERR;
 		}
 		sfp = NULL;
Index: ed/cbc.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/cbc.c,v
retrieving revision 1.13
diff -u -r1.13 cbc.c
--- ed/cbc.c	2001/03/05 02:15:37	1.13
+++ ed/cbc.c	2001/07/03 01:32:26
@@ -33,17 +33,11 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- *	from: @(#)bdes.c	5.5 (Berkeley) 6/27/91
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/cbc.c,v 1.13 2001/03/05 02:15:37 kris Exp $";
-#endif
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -183,7 +177,7 @@
 int
 get_keyword()
 {
-	register char *p;		/* used to obtain the key */
+	char *p;			/* used to obtain the key */
 	Desbuf msgbuf;			/* I/O buffer */
 
 	/*
@@ -209,9 +203,9 @@
  */
 void
 des_error(s)
-	char *s;		/* the message */
+	const char *s;		/* the message */
 {
-	(void)sprintf(errmsg, "%s", s ? s : strerror(errno));
+	(void)snprintf(errmsg, sizeof(errmsg), "%s", s ? s : strerror(errno));
 }
 
 /*
@@ -250,23 +244,23 @@
  * convert the key to a bit pattern
  */
 void
-expand_des_key(obuf, ibuf)
+expand_des_key(obuf, kbuf)
 	char *obuf;			/* bit pattern */
-	char *ibuf;			/* the key itself */
+	char *kbuf;			/* the key itself */
 {
-	register int i, j;		/* counter in a for loop */
+	int i, j;			/* counter in a for loop */
 	int nbuf[64];			/* used for hex/key translation */
 
 	/*
 	 * leading '0x' or '0X' == hex key
 	 */
-	if (ibuf[0] == '0' && (ibuf[1] == 'x' || ibuf[1] == 'X')) {
-		ibuf = &ibuf[2];
+	if (kbuf[0] == '0' && (kbuf[1] == 'x' || kbuf[1] == 'X')) {
+		kbuf = &kbuf[2];
 		/*
 		 * now translate it, bombing on any illegal hex digit
 		 */
-		for (i = 0; ibuf[i] && i < 16; i++)
-			if ((nbuf[i] = hex_to_binary((int) ibuf[i], 16)) == -1)
+		for (i = 0; kbuf[i] && i < 16; i++)
+			if ((nbuf[i] = hex_to_binary((int) kbuf[i], 16)) == -1)
 				des_error("bad hex digit in key");
 		while (i < 16)
 			nbuf[i++] = 0;
@@ -280,13 +274,13 @@
 	/*
 	 * leading '0b' or '0B' == binary key
 	 */
-	if (ibuf[0] == '0' && (ibuf[1] == 'b' || ibuf[1] == 'B')) {
-		ibuf = &ibuf[2];
+	if (kbuf[0] == '0' && (kbuf[1] == 'b' || kbuf[1] == 'B')) {
+		kbuf = &kbuf[2];
 		/*
 		 * now translate it, bombing on any illegal binary digit
 		 */
-		for (i = 0; ibuf[i] && i < 16; i++)
-			if ((nbuf[i] = hex_to_binary((int) ibuf[i], 2)) == -1)
+		for (i = 0; kbuf[i] && i < 16; i++)
+			if ((nbuf[i] = hex_to_binary((int) kbuf[i], 2)) == -1)
 				des_error("bad binary digit in key");
 		while (i < 64)
 			nbuf[i++] = 0;
@@ -300,7 +294,7 @@
 	/*
 	 * no special leader -- ASCII
 	 */
-	(void)strncpy(obuf, ibuf, 8);
+	(void)strncpy(obuf, kbuf, 8);
 }
 
 /*****************
@@ -321,8 +315,8 @@
 set_des_key(buf)
 	Desbuf buf;				/* key block */
 {
-	register int i, j;			/* counter in a for loop */
-	register int par;			/* parity counter */
+	int i, j;				/* counter in a for loop */
+	int par;				/* parity counter */
 
 	/*
 	 * if the parity is not preserved, flip it
@@ -391,20 +385,20 @@
 	char *msgbuf;		/* I/O buffer */
 	FILE *fp;			/* input file descriptor */
 {
-	Desbuf ibuf;	/* temp buffer for initialization vector */
-	register int n;		/* number of bytes actually read */
-	register int c;		/* used to test for EOF */
+	Desbuf tbuf;	/* temp buffer for initialization vector */
+	int n;			/* number of bytes actually read */
+	int c;			/* used to test for EOF */
 	int inverse = 1;	/* 0 to encrypt, 1 to decrypt */
 
 	if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) {
 		/*
 		 * do the transformation
 		 */
-		MEMCPY(BUFFER(ibuf), BUFFER(msgbuf), 8);
+		MEMCPY(BUFFER(tbuf), BUFFER(msgbuf), 8);
 		DES_XFORM(UBUFFER(msgbuf));
 		for (c = 0; c < 8; c++)
 			UCHAR(msgbuf, c) ^= UCHAR(ivec, c);
-		MEMCPY(BUFFER(ivec), BUFFER(ibuf), 8);
+		MEMCPY(BUFFER(ivec), BUFFER(tbuf), 8);
 		/*
 		 * if the last one, handle it specially
 		 */
Index: ed/ed.h
===================================================================
RCS file: /home/ncvs/src/bin/ed/ed.h,v
retrieving revision 1.14
diff -u -r1.14 ed.h
--- ed/ed.h	2001/05/29 18:03:13	1.14
+++ ed/ed.h	2001/07/03 01:32:27
@@ -105,7 +105,7 @@
 #define STRTOL(i, p) { \
 	if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
 	    errno == ERANGE) { \
-		sprintf(errmsg, "number out of range"); \
+		snprintf(errmsg, sizeof(errmsg), "number out of range"); \
 	    	i = 0; \
 		return ERR; \
 	} \
@@ -121,14 +121,14 @@
 	if ((b) != NULL) { \
 		if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
 			fprintf(stderr, "%s\n", strerror(errno)); \
-			sprintf(errmsg, "out of memory"); \
+			snprintf(errmsg, sizeof(errmsg), "out of memory"); \
 			SPL0(); \
 			return err; \
 		} \
 	} else { \
 		if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \
 			fprintf(stderr, "%s\n", strerror(errno)); \
-			sprintf(errmsg, "out of memory"); \
+			snprintf(errmsg, sizeof(errmsg), "out of memory"); \
 			SPL0(); \
 			return err; \
 		} \
@@ -146,7 +146,7 @@
 	SPL1(); \
 	if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
 		fprintf(stderr, "%s\n", strerror(errno)); \
-		sprintf(errmsg, "out of memory"); \
+		snprintf(errmsg, sizeof(errmsg), "out of memory"); \
 		SPL0(); \
 		return err; \
 	} \
@@ -190,7 +190,7 @@
 /* Local Function Declarations */
 void add_line_node __P((line_t *));
 int append_lines __P((long));
-int apply_subst_template __P((char *, regmatch_t *, int, int));
+int apply_subst_template __P((const char *, regmatch_t *, int, int));
 int build_active_list __P((int));
 int cbc_decode __P((char *, FILE *));
 int cbc_encode __P((char *, int, FILE *));
@@ -200,7 +200,7 @@
 int close_sbuf __P((void));
 int copy_lines __P((long));
 int delete_lines __P((long, long));
-void des_error __P((char *));
+void des_error __P((const char *));
 int display_lines __P((long, long, int));
 line_t *dup_line_node __P((line_t *));
 int exec_command __P((void));
@@ -236,16 +236,16 @@
 int join_lines __P((long, long));
 int mark_line_node __P((line_t *, int));
 int move_lines __P((long));
-line_t *next_active_node __P(());
+line_t *next_active_node __P((void));
 long next_addr __P((void));
 int open_sbuf __P((void));
 char *parse_char_class __P((char *));
 int pop_undo_stack __P((void));
 undo_t *push_undo_stack __P((int, long, long));
 int put_des_char __P((int, FILE *));
-char *put_sbuf_line __P((char *));
-int put_stream_line __P((FILE *, char *, int));
-int put_tty_line __P((char *, int, long, int));
+const char *put_sbuf_line __P((const char *));
+int put_stream_line __P((FILE *, const char *, int));
+int put_tty_line __P((const char *, int, long, int));
 void quit __P((int));
 long read_file __P((char *, long));
 long read_stream __P((FILE *, long));
@@ -259,7 +259,7 @@
 char *translit_text __P((char *, int, int, int));
 void unmark_line_node __P((line_t *));
 void unset_active_nodes __P((line_t *, line_t *));
-long write_file __P((char *, char *, long, long));
+long write_file __P((char *, const char *, long, long));
 long write_stream __P((FILE *, long, long));
 
 /* global buffers */
@@ -278,7 +278,7 @@
 /* global vars */
 extern long addr_last;
 extern long current_addr;
-extern char errmsg[];
+extern char errmsg[PATH_MAX + 40];
 extern long first_addr;
 extern int lineno;
 extern long second_addr;
Index: ed/glbl.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/glbl.c,v
retrieving revision 1.10
diff -u -r1.10 glbl.c
--- ed/glbl.c	2000/10/16 07:06:35	1.10
+++ ed/glbl.c	2001/07/03 01:32:27
@@ -27,12 +27,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/glbl.c,v 1.10 2000/10/16 07:06:35 brian Exp $";
-#endif
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -55,7 +51,7 @@
 	char delimiter;
 
 	if ((delimiter = *ibufp) == ' ' || delimiter == '\n') {
-		sprintf(errmsg, "invalid pattern delimiter");
+		snprintf(errmsg, sizeof(errmsg), "invalid pattern delimiter");
 		return ERR;
 	} else if ((pat = get_compiled_pattern()) == NULL)
 		return ERR;
@@ -115,13 +111,15 @@
 			if (n < 0)
 				return ERR;
 			else if (n == 0) {
-				sprintf(errmsg, "unexpected end-of-file");
+				snprintf(errmsg, sizeof(errmsg),
+				    "unexpected end-of-file");
 				return ERR;
 			} else if (n == 1 && !strcmp(ibuf, "\n"))
 				continue;
 			else if (n == 2 && !strcmp(ibuf, "&\n")) {
 				if (cmd == NULL) {
-					sprintf(errmsg, "no previous command");
+					snprintf(errmsg, sizeof(errmsg),
+					    "no previous command");
 					return ERR;
 				} else cmd = ocmd;
 			} else if ((cmd = get_extended_line(&n, 0)) == NULL)
@@ -166,7 +164,8 @@
 			if ((ts = (line_t **) realloc(active_list,
 			    (ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
 				fprintf(stderr, "%s\n", strerror(errno));
-				sprintf(errmsg, "out of memory");
+				snprintf(errmsg, sizeof(errmsg),
+				    "out of memory");
 				SPL0();
 				return ERR;
 			}
@@ -175,7 +174,8 @@
 			if ((ts = (line_t **) malloc((ti += MINBUFSZ) *
 			    sizeof(line_t **))) == NULL) {
 				fprintf(stderr, "%s\n", strerror(errno));
-				sprintf(errmsg, "out of memory");
+				snprintf(errmsg, sizeof(errmsg),
+				    "out of memory");
 				SPL0();
 				return ERR;
 			}
Index: ed/io.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/io.c,v
retrieving revision 1.10
diff -u -r1.10 io.c
--- ed/io.c	1999/08/27 23:14:14	1.10
+++ ed/io.c	2001/07/03 01:32:27
@@ -26,12 +26,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/io.c,v 1.10 1999/08/27 23:14:14 peter Exp $";
-#endif
 #endif /* not lint */
 
 #include "ed.h"
@@ -52,13 +48,13 @@
 	fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
 	if (fp == NULL) {
 		fprintf(stderr, "%s: %s\n", fn, strerror(errno));
-		sprintf(errmsg, "cannot open input file");
+		snprintf(errmsg, sizeof(errmsg), "cannot open input file");
 		return ERR;
 	} else if ((size = read_stream(fp, n)) < 0)
 		return ERR;
 	 else if (((*fn == '!') ?  pclose(fp) : fclose(fp)) < 0) {
 		fprintf(stderr, "%s: %s\n", fn, strerror(errno));
-		sprintf(errmsg, "cannot close input file");
+		snprintf(errmsg, sizeof(errmsg), "cannot close input file");
 		return ERR;
 	}
 	fprintf(stdout, !scripted ? "%lu\n" : "", size);
@@ -128,8 +124,8 @@
 get_stream_line(fp)
 	FILE *fp;
 {
-	register int c;
-	register int i = 0;
+	int c;
+	int i = 0;
 
 	while (((c = des ? get_des_char(fp) : getc(fp)) != EOF || (!feof(fp) &&
 	    !ferror(fp))) && c != '\n') {
@@ -142,7 +138,7 @@
 		sbuf[i++] = c;
 	else if (ferror(fp)) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "cannot read input file");
+		snprintf(errmsg, sizeof(errmsg), "cannot read input file");
 		return ERR;
 	} else if (i) {
 		sbuf[i++] = '\n';
@@ -157,7 +153,7 @@
 long
 write_file(fn, mode, n, m)
 	char *fn;
-	char *mode;
+	const char *mode;
 	long n;
 	long m;
 {
@@ -167,13 +163,13 @@
 	fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
 	if (fp == NULL) {
 		fprintf(stderr, "%s: %s\n", fn, strerror(errno));
-		sprintf(errmsg, "cannot open output file");
+		snprintf(errmsg, sizeof(errmsg), "cannot open output file");
 		return ERR;
 	} else if ((size = write_stream(fp, n, m)) < 0)
 		return ERR;
 	 else if (((*fn == '!') ?  pclose(fp) : fclose(fp)) < 0) {
 		fprintf(stderr, "%s: %s\n", fn, strerror(errno));
-		sprintf(errmsg, "cannot close output file");
+		snprintf(errmsg, sizeof(errmsg), "cannot close output file");
 		return ERR;
 	}
 	fprintf(stdout, !scripted ? "%lu\n" : "", size);
@@ -217,13 +213,13 @@
 int
 put_stream_line(fp, s, len)
 	FILE *fp;
-	char *s;
+	const char *s;
 	int len;
 {
 	while (len--)
 		if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
 			fprintf(stderr, "%s\n", strerror(errno));
-			sprintf(errmsg, "cannot write file");
+			snprintf(errmsg, sizeof(errmsg), "cannot write file");
 			return ERR;
 		}
 	return 0;
@@ -256,7 +252,8 @@
 		if ((n = get_tty_line()) < 0)
 			return NULL;
 		else if (n == 0 || ibuf[n - 1] != '\n') {
-			sprintf(errmsg, "unexpected end-of-file");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected end-of-file");
 			return NULL;
 		}
 		REALLOC(cvbuf, cvbufsz, l + n, NULL);
@@ -278,8 +275,8 @@
 int
 get_tty_line()
 {
-	register int oi = 0;
-	register int i = 0;
+	int oi = 0;
+	int i = 0;
 	int c;
 
 	for (;;)
@@ -297,7 +294,8 @@
 		case EOF:
 			if (ferror(stdin)) {
 				fprintf(stderr, "stdin: %s\n", strerror(errno));
-				sprintf(errmsg, "cannot read stdin");
+				snprintf(errmsg, sizeof(errmsg),
+				    "cannot read stdin");
 				clearerr(stdin);
 				ibufp = NULL;
 				return ERR;
@@ -325,7 +323,7 @@
 /* put_tty_line: print text to stdout */
 int
 put_tty_line(s, l, n, gflag)
-	char *s;
+	const char *s;
 	int l;
 	long n;
 	int gflag;
Index: ed/main.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/main.c,v
retrieving revision 1.20
diff -u -r1.20 main.c
--- ed/main.c	2001/06/28 22:06:27	1.20
+++ ed/main.c	2001/07/03 01:32:27
@@ -27,18 +27,14 @@
  */
 
 #ifndef lint
-static char * const copyright =
+static const char copyright[] =
 "@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/main.c,v 1.20 2001/06/28 22:06:27 dd Exp $";
-#endif
 #endif /* not lint */
 
 /*
@@ -100,8 +96,8 @@
 long current_addr;		/* current address in editor buffer */
 long addr_last;			/* last address in editor buffer */
 int lineno;			/* script line number */
-char *prompt;			/* command-line prompt */
-char *dps = "*";		/* default command-line prompt */
+const char *prompt;		/* command-line prompt */
+const char *dps = "*";		/* default command-line prompt */
 
 const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
 
@@ -169,7 +165,7 @@
 #endif
 	{
 		fputs("\n?\n", stderr);
-		sprintf(errmsg, "interrupt");
+		snprintf(errmsg, sizeof(errmsg), "interrupt");
 	} else {
 		init_buffers();
 		sigactive = 1;			/* enable signal handlers */
@@ -183,7 +179,8 @@
 		} else if (argc) {
 			fputs("?\n", stderr);
 			if (**argv == '\0')
-				sprintf(errmsg, "invalid filename");
+				snprintf(errmsg, sizeof(errmsg),
+				    "invalid filename");
 			if (!isatty(0))
 				quit(2);
 		}
@@ -201,7 +198,8 @@
 		} else if (n == 0) {
 			if (modified && !scripted) {
 				fputs("?\n", stderr);
-				sprintf(errmsg, "warning: file modified");
+				snprintf(errmsg, sizeof(errmsg),
+				    "warning: file modified");
 				if (!isatty(0)) {
 					fprintf(stderr, garrulous ?
 					    "script, line %d: %s\n" :
@@ -216,7 +214,8 @@
 				quit(0);
 		} else if (ibuf[n - 1] != '\n') {
 			/* discard line */
-			sprintf(errmsg, "unexpected end-of-file");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected end-of-file");
 			clearerr(stdin);
 			status = ERR;
 			continue;
@@ -234,7 +233,8 @@
 		case EMOD:
 			modified = 0;
 			fputs("?\n", stderr);		/* give warning */
-			sprintf(errmsg, "warning: file modified");
+			snprintf(errmsg, sizeof(errmsg),
+			    "warning: file modified");
 			if (!isatty(0)) {
 				fprintf(stderr, garrulous ?
 				    "script, line %d: %s\n" :
@@ -293,14 +293,16 @@
 
 #define SKIP_BLANKS() while (isspace((unsigned char)*ibufp) && *ibufp != '\n') ibufp++
 
-#define MUST_BE_FIRST() \
-	if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
+#define MUST_BE_FIRST() if (!first) {				\
+	snprintf(errmsg, sizeof(errmsg), "invalid address");	\
+	return ERR;						\
+}
 
 /*  next_addr: return the next line address in the command buffer */
 long
 next_addr()
 {
-	char *hd;
+	const char *hd;
 	long addr = current_addr;
 	long n;
 	int first = 1;
@@ -364,7 +366,8 @@
 			if (ibufp == hd)
 				return EOF;
 			else if (addr < 0 || addr_last < addr) {
-				sprintf(errmsg, "invalid address");
+				snprintf(errmsg, sizeof(errmsg),
+				    "invalid address");
 				return ERR;
 			} else
 				return addr;
@@ -383,10 +386,10 @@
 	if (extract_addr_range() < 0) \
 		return ERR; \
 	else if (addr_cnt == 0) { \
-		sprintf(errmsg, "destination expected"); \
+		snprintf(errmsg, sizeof(errmsg), "destination expected"); \
 		return ERR; \
 	} else if (second_addr < 0 || addr_last < second_addr) { \
-		sprintf(errmsg, "invalid address"); \
+		snprintf(errmsg, sizeof(errmsg), "invalid address"); \
 		return ERR; \
 	} \
 	addr = second_addr; \
@@ -402,7 +405,7 @@
 	if (extract_addr_range() < 0) \
 		return ERR; \
 	if (second_addr < 0 || addr_last < second_addr) { \
-		sprintf(errmsg, "invalid address"); \
+		snprintf(errmsg, sizeof(errmsg), "invalid address"); \
 		return ERR; \
 	} \
 	addr = second_addr; \
@@ -430,7 +433,7 @@
 		} \
 	} while (!done); \
 	if (*ibufp++ != '\n') { \
-		sprintf(errmsg, "invalid command suffix"); \
+		snprintf(errmsg, sizeof(errmsg), "invalid command suffix"); \
 		return ERR; \
 	} \
 }
@@ -499,10 +502,11 @@
 		/* fall through */
 	case 'E':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		} else if (!isspace((unsigned char)*ibufp)) {
-			sprintf(errmsg, "unexpected command suffix");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected command suffix");
 			return ERR;
 		} else if ((fnp = get_filename()) == NULL)
 			return ERR;
@@ -517,7 +521,7 @@
 		if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
-			sprintf(errmsg, "no current filename");
+			snprintf(errmsg, sizeof(errmsg), "no current filename");
 			return ERR;
 		}
 #endif
@@ -529,15 +533,16 @@
 		break;
 	case 'f':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		} else if (!isspace((unsigned char)*ibufp)) {
-			sprintf(errmsg, "unexpected command suffix");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected command suffix");
 			return ERR;
 		} else if ((fnp = get_filename()) == NULL)
 			return ERR;
 		else if (*fnp == '!') {
-			sprintf(errmsg, "invalid redirection");
+			snprintf(errmsg, sizeof(errmsg), "invalid redirection");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -549,7 +554,8 @@
 	case 'G':
 	case 'V':
 		if (isglobal) {
-			sprintf(errmsg, "cannot nest global commands");
+			snprintf(errmsg, sizeof(errmsg),
+			    "cannot nest global commands");
 			return ERR;
 		} else if (check_addr_range(1, addr_last) < 0)
 			return ERR;
@@ -563,7 +569,8 @@
 		break;
 	case 'h':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -571,7 +578,8 @@
 		break;
 	case 'H':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -580,7 +588,7 @@
 		break;
 	case 'i':
 		if (second_addr == 0) {
-			sprintf(errmsg, "invalid address");
+			snprintf(errmsg, sizeof(errmsg), "invalid address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -600,7 +608,7 @@
 	case 'k':
 		c = *ibufp++;
 		if (second_addr == 0) {
-			sprintf(errmsg, "invalid address");
+			snprintf(errmsg, sizeof(errmsg), "invalid address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -620,7 +628,7 @@
 			return ERR;
 		GET_THIRD_ADDR(addr);
 		if (first_addr <= addr && addr < second_addr) {
-			sprintf(errmsg, "invalid destination");
+			snprintf(errmsg, sizeof(errmsg), "invalid destination");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -646,7 +654,7 @@
 		break;
 	case 'P':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -655,7 +663,7 @@
 	case 'q':
 	case 'Q':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -663,7 +671,8 @@
 		break;
 	case 'r':
 		if (!isspace((unsigned char)*ibufp)) {
-			sprintf(errmsg, "unexpected command suffix");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected command suffix");
 			return ERR;
 		} else if (addr_cnt == 0)
 			second_addr = addr_last;
@@ -675,7 +684,7 @@
 			strcpy(old_filename, fnp);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
-			sprintf(errmsg, "no current filename");
+			snprintf(errmsg, sizeof(errmsg), "no current filename");
 			return ERR;
 		}
 #endif
@@ -710,18 +719,21 @@
 				break;
 			default:
 				if (sflags) {
-					sprintf(errmsg, "invalid command suffix");
+					snprintf(errmsg, sizeof(errmsg),
+					    "invalid command suffix");
 					return ERR;
 				}
 			}
 		} while (sflags && *ibufp != '\n');
 		if (sflags && !pat) {
-			sprintf(errmsg, "no previous substitution");
+			snprintf(errmsg, sizeof(errmsg),
+			    "no previous substitution");
 			return ERR;
 		} else if (sflags & SGG)
 			sgnum = 0;		/* override numeric arg */
 		if (*ibufp != '\n' && *(ibufp + 1) == '\n') {
-			sprintf(errmsg, "invalid pattern delimiter");
+			snprintf(errmsg, sizeof(errmsg),
+			    "invalid pattern delimiter");
 			return ERR;
 		}
 		tpat = pat;
@@ -782,7 +794,7 @@
 		break;
 	case 'u':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
@@ -796,7 +808,8 @@
 			ibufp++;
 		}
 		if (!isspace((unsigned char)*ibufp)) {
-			sprintf(errmsg, "unexpected command suffix");
+			snprintf(errmsg, sizeof(errmsg),
+			    "unexpected command suffix");
 			return ERR;
 		} else if ((fnp = get_filename()) == NULL)
 			return ERR;
@@ -809,7 +822,7 @@
 			strcpy(old_filename, fnp);
 #ifdef BACKWARDS
 		if (*fnp == '\0' && *old_filename == '\0') {
-			sprintf(errmsg, "no current filename");
+			snprintf(errmsg, sizeof(errmsg), "no current filename");
 			return ERR;
 		}
 #endif
@@ -823,14 +836,14 @@
 		break;
 	case 'x':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		}
 		GET_COMMAND_SUFFIX();
 #ifdef DES
 		des = get_keyword();
 #else
-		sprintf(errmsg, "crypt unavailable");
+		snprintf(errmsg, sizeof(errmsg), "crypt unavailable");
 		return ERR;
 #endif
 		break;
@@ -855,7 +868,7 @@
 		break;
 	case '!':
 		if (addr_cnt > 0) {
-			sprintf(errmsg, "unexpected address");
+			snprintf(errmsg, sizeof(errmsg), "unexpected address");
 			return ERR;
 		} else if ((sflags = get_shell_command()) < 0)
 			return ERR;
@@ -874,7 +887,7 @@
 			return ERR;
 		break;
 	default:
-		sprintf(errmsg, "unknown command");
+		snprintf(errmsg, sizeof(errmsg), "unknown command");
 		return ERR;
 	}
 	return gflag;
@@ -892,7 +905,7 @@
 	}
 	if (first_addr > second_addr || 1 > first_addr ||
 	    second_addr > addr_last) {
-		sprintf(errmsg, "invalid address");
+		snprintf(errmsg, sizeof(errmsg), "invalid address");
 		return ERR;
 	}
 	return 0;
@@ -923,7 +936,7 @@
 				return n;
 	       }
 	} while (n != current_addr);
-	sprintf(errmsg, "no match");
+	snprintf(errmsg, sizeof(errmsg), "no match");
 	return  ERR;
 }
 
@@ -940,7 +953,7 @@
 	if (*ibufp != '\n') {
 		SKIP_BLANKS();
 		if (*ibufp == '\n') {
-			sprintf(errmsg, "invalid filename");
+			snprintf(errmsg, sizeof(errmsg), "invalid filename");
 			return NULL;
 		} else if ((ibufp = get_extended_line(&n, 1)) == NULL)
 			return NULL;
@@ -952,13 +965,13 @@
 				printf("%s\n", shcmd + 1);
 			return shcmd;
 		} else if (n > PATH_MAX - 1) {
-			sprintf(errmsg, "filename too long");
+			snprintf(errmsg, sizeof(errmsg), "filename too long");
 			return  NULL;
 		}
 	}
 #ifndef BACKWARDS
 	else if (*old_filename == '\0') {
-		sprintf(errmsg, "no current filename");
+		snprintf(errmsg, sizeof(errmsg), "no current filename");
 		return  NULL;
 	}
 #endif
@@ -983,7 +996,7 @@
 	int j = 0;
 
 	if (red) {
-		sprintf(errmsg, "shell access restricted");
+		snprintf(errmsg, sizeof(errmsg), "shell access restricted");
 		return ERR;
 	} else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
 		return ERR;
@@ -1008,7 +1021,8 @@
 			else if (shcmd == NULL)
 #endif
 			{
-				sprintf(errmsg, "no previous command");
+				snprintf(errmsg, sizeof(errmsg),
+				    "no previous command");
 				return ERR;
 			} else {
 				REALLOC(buf, n, i + shcmdi, ERR);
@@ -1019,7 +1033,8 @@
 			break;
 		case '%':
 			if (*old_filename  == '\0') {
-				sprintf(errmsg, "no current filename");
+				snprintf(errmsg, sizeof(errmsg),
+				    "no current filename");
 				return ERR;
 			}
 			j = strlen(s = strip_escapes(old_filename));
@@ -1043,8 +1058,8 @@
 	long n;
 {
 	int l;
-	char *lp = ibuf;
-	char *eot;
+	const char *lp = ibuf;
+	const char *eot;
 	undo_t *up = NULL;
 
 	for (current_addr = n;;) {
@@ -1246,7 +1261,7 @@
 	char *s;
 
 	if (!from) {
-		sprintf(errmsg, "invalid address");
+		snprintf(errmsg, sizeof(errmsg), "invalid address");
 		return ERR;
 	}
 	ep = get_addressed_line_node(INC_MOD(to, addr_last));
@@ -1273,7 +1288,7 @@
 	int n;
 {
 	if (!islower((unsigned char)n)) {
-		sprintf(errmsg, "invalid mark character");
+		snprintf(errmsg, sizeof(errmsg), "invalid mark character");
 		return ERR;
 	} else if (mark[n - 'a'] == NULL)
 		markno++;
@@ -1288,7 +1303,7 @@
 	int n;
 {
 	if (!islower((unsigned char)n)) {
-		sprintf(errmsg, "invalid mark character");
+		snprintf(errmsg, sizeof(errmsg), "invalid mark character");
 		return ERR;
 	}
 	return get_line_node_addr(mark[n - 'a']);
@@ -1319,7 +1334,7 @@
 
 	if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "out of memory");
+		snprintf(errmsg, sizeof(errmsg), "out of memory");
 		return NULL;
 	}
 	np->seek = lp->seek;
@@ -1385,12 +1400,13 @@
 {
 	char *hup = NULL;		/* hup filename */
 	char *s;
+	char ed_hup[] = "ed.hup";
 	int n;
 
 	if (!sigactive)
 		quit(1);
 	sigflags &= ~(1 << (signo - 1));
-	if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
+	if (addr_last && write_file(ed_hup, "w", 1, addr_last) < 0 &&
 	    (s = getenv("HOME")) != NULL &&
 	    (n = strlen(s)) + 8 <= PATH_MAX &&	/* "ed.hup" + '/' */
 	    (hup = (char *) malloc(n + 10)) != NULL) {
@@ -1444,7 +1460,7 @@
 	char *s;
 {
 	if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
-		sprintf(errmsg, "shell access restricted");
+		snprintf(errmsg, sizeof(errmsg), "shell access restricted");
 		return 0;
 	}
 	return 1;
Index: ed/re.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/re.c,v
retrieving revision 1.16
diff -u -r1.16 re.c
--- ed/re.c	2001/05/29 18:03:14	1.16
+++ ed/re.c	2001/07/03 01:32:27
@@ -27,12 +27,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/re.c,v 1.16 2001/05/29 18:03:14 imp Exp $";
-#endif
 #endif /* not lint */
 
 #include "ed.h"
@@ -54,10 +50,11 @@
 	int n;
 
 	if ((delimiter = *ibufp) == ' ') {
-		sprintf(errmsg, "invalid pattern delimiter");
+		snprintf(errmsg, sizeof(errmsg), "invalid pattern delimiter");
 		return NULL;
 	} else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) {
-		if (!exp) sprintf(errmsg, "no previous pattern");
+		if (!exp)
+			snprintf(errmsg, sizeof(errmsg), "no previous pattern");
 		return exp;
 	} else if ((exps = extract_pattern(delimiter)) == NULL)
 		return NULL;
@@ -66,7 +63,7 @@
 		regfree(exp);
 	else if ((exp = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "out of memory");
+		snprintf(errmsg, sizeof(errmsg), "out of memory");
 		return NULL;
 	}
 	patlock = 0;
@@ -97,13 +94,15 @@
 			break;
 		case '[':
 			if ((nd = parse_char_class(++nd)) == NULL) {
-				sprintf(errmsg, "unbalanced brackets ([])");
+				snprintf(errmsg, sizeof(errmsg),
+				    "unbalanced brackets ([])");
 				return NULL;
 			}
 			break;
 		case '\\':
 			if (*++nd == '\n') {
-				sprintf(errmsg, "trailing backslash (\\)");
+				snprintf(errmsg, sizeof(errmsg),
+				    "trailing backslash (\\)");
 				return NULL;
 			}
 			break;
Index: ed/sub.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/sub.c,v
retrieving revision 1.12
diff -u -r1.12 sub.c
--- ed/sub.c	1999/08/27 23:14:15	1.12
+++ ed/sub.c	2001/07/03 01:32:27
@@ -27,12 +27,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/sub.c,v 1.12 1999/08/27 23:14:15 peter Exp $";
-#endif
 #endif /* not lint */
 
 #include "ed.h"
@@ -86,7 +82,9 @@
 
 	if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
 		ibufp++;
-		if (!rhbuf) sprintf(errmsg, "no previous substitution");
+		if (!rhbuf)
+			snprintf(errmsg, sizeof(errmsg),
+			    "no previous substitution");
 		return rhbuf;
 	}
 	while (*ibufp != delimiter) {
@@ -124,8 +122,8 @@
 	int kth;
 {
 	undo_t *up;
-	char *txt;
-	char *eot;
+	const char *txt;
+	const char *eot;
 	long lc;
 	long xa = current_addr;
 	int nsubs = 0;
@@ -163,7 +161,7 @@
 	}
 	current_addr = xa;
 	if  (nsubs == 0 && !(gflag & GLB)) {
-		sprintf(errmsg, "no match");
+		snprintf(errmsg, sizeof(errmsg), "no match");
 		return ERR;
 	} else if ((gflag & (GPR | GLS | GNP)) &&
 	    display_lines(current_addr, current_addr, gflag) < 0)
@@ -222,7 +220,8 @@
 		i = eot - txt;
 		REALLOC(rbuf, rbufsz, off + i + 2, ERR);
 		if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) {
-			sprintf(errmsg, "infinite substitution loop");
+			snprintf(errmsg, sizeof(errmsg),
+			    "infinite substitution loop");
 			return  ERR;
 		}
 		if (isbinary)
@@ -238,7 +237,7 @@
    return offset to end of modified text */
 int
 apply_subst_template(boln, rm, off, re_nsub)
-	char *boln;
+	const char *boln;
 	regmatch_t *rm;
 	int off;
 	int re_nsub;
Index: ed/undo.c
===================================================================
RCS file: /home/ncvs/src/bin/ed/undo.c,v
retrieving revision 1.9
diff -u -r1.9 undo.c
--- ed/undo.c	1999/08/27 23:14:15	1.9
+++ ed/undo.c	2001/07/03 01:32:27
@@ -26,12 +26,8 @@
  */
 
 #ifndef lint
-#if 0
-static char * const rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
   "$FreeBSD: src/bin/ed/undo.c,v 1.9 1999/08/27 23:14:15 peter Exp $";
-#endif
 #endif /* not lint */
 
 #include "ed.h"
@@ -55,7 +51,7 @@
 	if (ustack == NULL &&
 	    (ustack = (undo_t *) malloc((usize = USIZE) * sizeof(undo_t))) == NULL) {
 		fprintf(stderr, "%s\n", strerror(errno));
-		sprintf(errmsg, "out of memory");
+		snprintf(errmsg, sizeof(errmsg), "out of memory");
 		return NULL;
 	}
 #endif
@@ -70,7 +66,7 @@
 	}
 	/* out of memory - release undo stack */
 	fprintf(stderr, "%s\n", strerror(errno));
-	sprintf(errmsg, "out of memory");
+	snprintf(errmsg, sizeof(errmsg), "out of memory");
 	clear_undo_stack();
 	free(ustack);
 	ustack = NULL;
@@ -98,7 +94,7 @@
 	long o_addr_last = addr_last;
 
 	if (u_current_addr == -1 || u_addr_last == -1) {
-		sprintf(errmsg, "nothing to undo");
+		snprintf(errmsg, sizeof(errmsg), "nothing to undo");
 		return ERR;
 	} else if (u_p)
 		modified = 1;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107030217.f632HOT06228>