Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/ed sprintf considered harmful
details: https://anonhg.NetBSD.org/src/rev/70d3d90eefde
branches: trunk
changeset: 794747:70d3d90eefde
user: dholland <dholland%NetBSD.org@localhost>
date: Sun Mar 23 05:06:42 2014 +0000
description:
sprintf considered harmful
diffstat:
bin/ed/buf.c | 24 ++++++------
bin/ed/cbc.c | 6 +-
bin/ed/ed.h | 13 +++---
bin/ed/glbl.c | 14 +++---
bin/ed/io.c | 20 +++++-----
bin/ed/main.c | 104 +++++++++++++++++++++++++++++-----------------------------
bin/ed/re.c | 25 ++++++++++---
bin/ed/sub.c | 12 +++--
bin/ed/undo.c | 10 ++--
9 files changed, 121 insertions(+), 107 deletions(-)
diffs (truncated from 951 to 300 lines):
diff -r 2e6024d25a1d -r 70d3d90eefde bin/ed/buf.c
--- a/bin/ed/buf.c Sun Mar 23 04:58:16 2014 +0000
+++ b/bin/ed/buf.c Sun Mar 23 05:06:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.26 2006/03/17 14:37:14 rumble Exp $ */
+/* $NetBSD: buf.c,v 1.27 2014/03/23 05:06:42 dholland Exp $ */
/* buf.c: This file contains the scratch-file buffer routines for the
ed line editor. */
@@ -33,7 +33,7 @@
#if 0
static char *rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
#else
-__RCSID("$NetBSD: buf.c,v 1.26 2006/03/17 14:37:14 rumble Exp $");
+__RCSID("$NetBSD: buf.c,v 1.27 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@@ -70,7 +70,7 @@
sfseek = lp->seek;
if (fseek(sfp, sfseek, SEEK_SET) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot seek temp file");
+ seterrmsg("cannot seek temp file");
return NULL;
}
}
@@ -78,7 +78,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");
+ seterrmsg("cannot read temp file");
return NULL;
}
sfseek += len; /* update file position */
@@ -98,14 +98,14 @@
if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ seterrmsg("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");
+ seterrmsg("line too long");
free(lp);
return NULL;
}
@@ -114,7 +114,7 @@
if (seek_write) {
if (fseek(sfp, 0L, SEEK_END) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot seek temp file");
+ seterrmsg("cannot seek temp file");
free(lp);
return NULL;
}
@@ -125,7 +125,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");
+ seterrmsg("cannot write temp file");
free(lp);
return NULL;
}
@@ -160,7 +160,7 @@
while (cp != lp && (cp = cp->q_forw) != &buffer_head)
n++;
if (n && cp == &buffer_head) {
- sprintf(errmsg, "invalid address");
+ seterrmsg("invalid address");
return ERR;
}
return n;
@@ -222,7 +222,7 @@
(void)asprintf(&sfn, "%s/ed.XXXXXX", tmp);
if (sfn == NULL) {
warn(NULL);
- sprintf(errmsg, "could not allocate memory");
+ seterrmsg("could not allocate memory");
umask(u);
return ERR;
}
@@ -232,7 +232,7 @@
if (fd != -1)
close(fd);
warn("%s", sfn);
- sprintf(errmsg, "cannot open temp file");
+ seterrmsg("cannot open temp file");
umask(u);
return ERR;
}
@@ -248,7 +248,7 @@
if (sfp) {
if (fclose(sfp) < 0) {
fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
- sprintf(errmsg, "cannot close temp file");
+ seterrmsg("cannot close temp file");
return ERR;
}
sfp = NULL;
diff -r 2e6024d25a1d -r 70d3d90eefde bin/ed/cbc.c
--- a/bin/ed/cbc.c Sun Mar 23 04:58:16 2014 +0000
+++ b/bin/ed/cbc.c Sun Mar 23 05:06:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cbc.c,v 1.22 2010/06/09 19:20:18 riz Exp $ */
+/* $NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $ */
/* cbc.c: This file contains the encryption routines for the ed line editor */
/*-
@@ -72,7 +72,7 @@
#if 0
static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
#else
-__RCSID("$NetBSD: cbc.c,v 1.22 2010/06/09 19:20:18 riz Exp $");
+__RCSID("$NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@@ -252,7 +252,7 @@
static void
des_error(const char *s /* the message */)
{
- (void)sprintf(errmsg, "%s", s ? s : strerror(errno));
+ seterrmsg("%s", s ? s : strerror(errno));
}
/*
diff -r 2e6024d25a1d -r 70d3d90eefde bin/ed/ed.h
--- a/bin/ed/ed.h Sun Mar 23 04:58:16 2014 +0000
+++ b/bin/ed/ed.h Sun Mar 23 05:06:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ed.h,v 1.35 2011/08/29 14:51:18 joerg Exp $ */
+/* $NetBSD: ed.h,v 1.36 2014/03/23 05:06:42 dholland Exp $ */
/* ed.h: type and constant definitions for the ed editor. */
/*
@@ -115,7 +115,7 @@
errno = 0 ; \
if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
errno == ERANGE) { \
- sprintf(errmsg, "number out of range"); \
+ seterrmsg("number out of range"); \
i = 0; \
return ERR; \
} \
@@ -131,14 +131,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"); \
+ seterrmsg("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"); \
+ seterrmsg("out of memory"); \
SPL0(); \
return err; \
} \
@@ -156,7 +156,7 @@
SPL1(); \
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
- sprintf(errmsg, "out of memory"); \
+ seterrmsg("out of memory"); \
SPL0(); \
return err; \
} \
@@ -257,6 +257,7 @@
void unset_active_nodes(line_t *, line_t *);
long write_file(const char *, const char *, long, long);
long write_stream(FILE *, long, long);
+void seterrmsg(const char *, ...);
/* global buffers */
extern char stdinbuf[];
@@ -284,7 +285,7 @@
extern int des;
extern int newline_added; /* io.c */
extern int patlock;
-extern char errmsg[]; /* re.c */
+extern char errmsg[]; /* re.c */
extern long u_current_addr; /* undo.c */
extern long u_addr_last; /* undo.c */
#if defined(sun) && !defined(__SVR4)
diff -r 2e6024d25a1d -r 70d3d90eefde bin/ed/glbl.c
--- a/bin/ed/glbl.c Sun Mar 23 04:58:16 2014 +0000
+++ b/bin/ed/glbl.c Sun Mar 23 05:06:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: glbl.c,v 1.6 2005/06/26 19:10:49 christos Exp $ */
+/* $NetBSD: glbl.c,v 1.7 2014/03/23 05:06:42 dholland Exp $ */
/* glob.c: This file contains the global command routines for the ed line
editor */
@@ -33,7 +33,7 @@
#if 0
static char *rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp";
#else
-__RCSID("$NetBSD: glbl.c,v 1.6 2005/06/26 19:10:49 christos Exp $");
+__RCSID("$NetBSD: glbl.c,v 1.7 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@@ -54,7 +54,7 @@
char delimiter;
if ((delimiter = *ibufp) == ' ' || delimiter == '\n') {
- sprintf(errmsg, "invalid pattern delimiter");
+ seterrmsg("invalid pattern delimiter");
return ERR;
} else if ((pat = get_compiled_pattern()) == NULL)
return ERR;
@@ -114,13 +114,13 @@
if (n < 0)
return ERR;
else if (n == 0) {
- sprintf(errmsg, "unexpected end-of-file");
+ seterrmsg("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");
+ seterrmsg("no previous command");
return ERR;
} else cmd = ocmd;
} else if ((cmd = get_extended_line(&n, 0)) == NULL)
@@ -164,7 +164,7 @@
if ((ts = (line_t **) realloc(active_list,
(ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ seterrmsg("out of memory");
SPL0();
return ERR;
}
@@ -173,7 +173,7 @@
if ((ts = (line_t **) malloc((ti += MINBUFSZ) *
sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ seterrmsg("out of memory");
SPL0();
return ERR;
}
diff -r 2e6024d25a1d -r 70d3d90eefde bin/ed/io.c
--- a/bin/ed/io.c Sun Mar 23 04:58:16 2014 +0000
+++ b/bin/ed/io.c Sun Mar 23 05:06:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $ */
+/* $NetBSD: io.c,v 1.10 2014/03/23 05:06:42 dholland Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
/*-
@@ -32,7 +32,7 @@
#if 0
static char *rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
#else
-__RCSID("$NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $");
+__RCSID("$NetBSD: io.c,v 1.10 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@@ -50,13 +50,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");
+ seterrmsg("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");
+ seterrmsg("cannot close input file");
return ERR;
}
if (!scripted)
@@ -136,7 +136,7 @@
sbuf[i++] = c;
else if (ferror(fp)) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot read input file");
+ seterrmsg("cannot read input file");
return ERR;
} else if (i) {
sbuf[i++] = '\n';
@@ -157,13 +157,13 @@
Home |
Main Index |
Thread Index |
Old Index