-/* $OpenBSD: buf.c,v 1.4 1996/06/25 00:26:02 deraadt Exp $ */
+/* $OpenBSD: buf.c,v 1.5 1996/09/15 22:25:54 millert Exp $ */
/* $NetBSD: buf.c,v 1.15 1995/04/23 10:07:28 cgd Exp $ */
/* buf.c: This file contains the scratch-file buffer rountines for the
#if 0
static char *rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: buf.c,v 1.4 1996/06/25 00:26:02 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: buf.c,v 1.5 1996/09/15 22:25:54 millert Exp $";
#endif
#endif /* not lint */
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;
}
}
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 */
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;
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);
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;
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;
if (fd != -1)
close(fd);
fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
- sprintf(errmsg, "cannot open temp file");
+ snprintf(errmsg, sizeof(errmsg), "cannot open temp file");
umask(u);
return ERR;
}
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;
-/* $OpenBSD: cbc.c,v 1.2 1996/06/23 14:19:59 deraadt Exp $ */
+/* $OpenBSD: cbc.c,v 1.3 1996/09/15 22:25:54 millert Exp $ */
/* $NetBSD: cbc.c,v 1.9 1995/03/21 09:04:36 cgd Exp $ */
/* cbc.c: This file contains the encryption routines for the ed line editor */
#if 0
static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: cbc.c,v 1.2 1996/06/23 14:19:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cbc.c,v 1.3 1996/09/15 22:25:54 millert Exp $";
#endif
#endif /* not lint */
des_error(s)
char *s; /* the message */
{
- (void)sprintf(errmsg, "%s", s ? s : strerror(errno));
+ (void)snprintf(errmsg, sizeof(errmsg), "%s", s ? s : strerror(errno));
}
/*
-/* $OpenBSD: ed.h,v 1.3 1996/08/22 00:35:17 deraadt Exp $ */
+/* $OpenBSD: ed.h,v 1.4 1996/09/15 22:25:55 millert Exp $ */
/* $NetBSD: ed.h,v 1.23 1995/03/21 09:04:40 cgd Exp $ */
/* ed.h: type and constant definitions for the ed editor. */
#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; \
} \
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; \
} \
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; \
} \
/* global vars */
extern long addr_last;
extern long current_addr;
-extern char errmsg[];
+extern char errmsg[MAXPATHLEN + 40];
extern long first_addr;
extern int lineno;
extern long second_addr;
-/* $OpenBSD: glbl.c,v 1.2 1996/06/23 14:20:01 deraadt Exp $ */
+/* $OpenBSD: glbl.c,v 1.3 1996/09/15 22:25:55 millert Exp $ */
/* $NetBSD: glbl.c,v 1.2 1995/03/21 09:04:41 cgd Exp $ */
/* glob.c: This file contains the global command routines for the ed line
#if 0
static char *rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: glbl.c,v 1.2 1996/06/23 14:20:01 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: glbl.c,v 1.3 1996/09/15 22:25:55 millert Exp $";
#endif
#endif /* not lint */
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;
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)
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;
}
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;
}
-/* $OpenBSD: io.c,v 1.2 1996/06/23 14:20:02 deraadt Exp $ */
+/* $OpenBSD: io.c,v 1.3 1996/09/15 22:25:56 millert Exp $ */
/* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
#if 0
static char *rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: io.c,v 1.2 1996/06/23 14:20:02 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: io.c,v 1.3 1996/09/15 22:25:56 millert Exp $";
#endif
#endif /* not lint */
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(stderr, !scripted ? "%lu\n" : "", size);
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';
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(stderr, !scripted ? "%lu\n" : "", size);
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;
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);
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;
-/* $OpenBSD: main.c,v 1.2 1996/06/23 14:20:02 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.3 1996/09/15 22:25:57 millert Exp $ */
/* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */
/* main.c: This file contains the main control and user-interface routines
#if 0
static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.2 1996/06/23 14:20:02 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.3 1996/09/15 22:25:57 millert Exp $";
#endif
#endif /* not lint */
char *usage = "usage: %s [-] [-sx] [-p string] [name]\n";
-extern char errmsg[];
extern int optind;
extern char *optarg;
#endif
{
fputs("\n?\n", stderr);
- sprintf(errmsg, "interrupt");
+ snprintf(errmsg, sizeof(errmsg), "interrupt");
} else {
init_buffers();
sigactive = 1; /* enable signal handlers */
} else if (argc) {
fputs("?\n", stderr);
if (**argv == '\0')
- sprintf(errmsg, "invalid filename");
+ snprintf(errmsg, sizeof(errmsg), "invalid filename");
if (!isatty(0))
quit(2);
}
} 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" :
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;
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" :
#define SKIP_BLANKS() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
#define MUST_BE_FIRST() \
- if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
+ if (!first) { snprintf(errmsg, sizeof(errmsg), "invalid address"); return ERR; }
/* next_addr: return the next line address in the command buffer */
long
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;
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; \
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; \
} \
} while (!done); \
if (*ibufp++ != '\n') { \
- sprintf(errmsg, "invalid command suffix"); \
+ snprintf(errmsg, sizeof(errmsg), "invalid command suffix"); \
return ERR; \
} \
}
/* fall through */
case 'E':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
} else if (!isspace(*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ snprintf(errmsg, sizeof(errmsg),
+ "unexpected command suffix");
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
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
break;
case 'f':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
} else if (!isspace(*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();
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;
break;
case 'h':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
break;
case 'H':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
break;
case 'i':
if (second_addr == 0) {
- sprintf(errmsg, "invalid address");
+ snprintf(errmsg, sizeof(errmsg), "invalid address");
return ERR;
}
GET_COMMAND_SUFFIX();
case 'k':
c = *ibufp++;
if (second_addr == 0) {
- sprintf(errmsg, "invalid address");
+ snprintf(errmsg, sizeof(errmsg), "invalid address");
return ERR;
}
GET_COMMAND_SUFFIX();
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();
break;
case 'P':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
case 'q':
case 'Q':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
break;
case 'r':
if (!isspace(*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ snprintf(errmsg, sizeof(errmsg),
+ "unexpected command suffix");
return ERR;
} else if (addr_cnt == 0)
second_addr = addr_last;
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
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;
break;
case 'u':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ snprintf(errmsg, sizeof(errmsg), "unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
ibufp++;
}
if (!isspace(*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ snprintf(errmsg, sizeof(errmsg),
+ "unexpected command suffix");
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
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
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;
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;
return ERR;
break;
default:
- sprintf(errmsg, "unknown command");
+ snprintf(errmsg, sizeof(errmsg), "unknown command");
return ERR;
}
return gflag;
}
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;
return n;
}
} while (n != current_addr);
- sprintf(errmsg, "no match");
+ snprintf(errmsg, sizeof(errmsg), "no match");
return ERR;
}
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;
if (n) printf("%s\n", shcmd + 1);
return shcmd;
} else if (n - 1 > MAXPATHLEN) {
- 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
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;
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);
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));
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));
int n;
{
if (!islower(n)) {
- sprintf(errmsg, "invalid mark character");
+ snprintf(errmsg, sizeof(errmsg), "invalid mark character");
return ERR;
} else if (mark[n - 'a'] == NULL)
markno++;
int n;
{
if (!islower(n)) {
- sprintf(errmsg, "invalid mark character");
+ snprintf(errmsg, sizeof(errmsg), "invalid mark character");
return ERR;
}
return get_line_node_addr(mark[n - 'a']);
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;
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;
-/* $OpenBSD: re.c,v 1.2 1996/06/23 14:20:03 deraadt Exp $ */
+/* $OpenBSD: re.c,v 1.3 1996/09/15 22:25:57 millert Exp $ */
/* $NetBSD: re.c,v 1.14 1995/03/21 09:04:48 cgd Exp $ */
/* re.c: This file contains the regular expression interface routines for
#if 0
static char *rcsid = "@(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: re.c,v 1.2 1996/06/23 14:20:03 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: re.c,v 1.3 1996/09/15 22:25:57 millert Exp $";
#endif
#endif /* not lint */
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;
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;
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;
-/* $OpenBSD: sub.c,v 1.2 1996/06/23 14:20:04 deraadt Exp $ */
+/* $OpenBSD: sub.c,v 1.3 1996/09/15 22:25:58 millert Exp $ */
/* $NetBSD: sub.c,v 1.4 1995/03/21 09:04:50 cgd Exp $ */
/* sub.c: This file contains the substitution routines for the ed
#if 0
static char *rcsid = "@(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: sub.c,v 1.2 1996/06/23 14:20:04 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: sub.c,v 1.3 1996/09/15 22:25:58 millert Exp $";
#endif
#endif /* not lint */
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) {
}
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)
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)
-/* $OpenBSD: undo.c,v 1.2 1996/06/23 14:20:04 deraadt Exp $ */
+/* $OpenBSD: undo.c,v 1.3 1996/09/15 22:25:58 millert Exp $ */
/* $NetBSD: undo.c,v 1.2 1995/03/21 09:04:52 cgd Exp $ */
/* undo.c: This file contains the undo routines for the ed line editor */
#if 0
static char *rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp";
#else
-static char rcsid[] = "$OpenBSD: undo.c,v 1.2 1996/06/23 14:20:04 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: undo.c,v 1.3 1996/09/15 22:25:58 millert Exp $";
#endif
#endif /* not lint */
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
}
/* 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;
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;
-/* $OpenBSD: expr.c,v 1.3 1996/06/23 14:20:10 deraadt Exp $ */
+/* $OpenBSD: expr.c,v 1.4 1996/09/15 22:27:38 millert Exp $ */
/* $NetBSD: expr.c,v 1.3.6.1 1996/06/04 20:41:47 cgd Exp $ */
/*
if (tmp == NULL) {
err(2, NULL);
}
- sprintf(tmp, "%d", vp->u.i);
+ snprintf(tmp, 25, "%d", vp->u.i);
vp->type = string;
vp->u.s = tmp;
}