summaryrefslogtreecommitdiff
path: root/lib/libtermlib/tparm.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-12-16 03:10:06 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-12-16 03:10:06 +0000
commitf527d97d86185c7c81a3f99755ae684452b889b9 (patch)
tree85e5aca717f8e0b426774c8eb5f3d412ac1054ce /lib/libtermlib/tparm.c
parent7a104c2751a77c9c1c1b58b8d0f3d67e53f62567 (diff)
tparm() now returns NULL for buffers that would be >= 256 (termcap
size limit). Also, make _tparm take a size argument. This isn't strictly necesary as we know the size of the buffer and this function is only used internally but this has the added benefit of making _tparm == GNU tparam if we ever want to export it as such. There are reported to be problems with emacs when native libtermlib has tparam() so we keep this private for now.
Diffstat (limited to 'lib/libtermlib/tparm.c')
-rw-r--r--lib/libtermlib/tparm.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/lib/libtermlib/tparm.c b/lib/libtermlib/tparm.c
index 0b545a77f10..082c480543e 100644
--- a/lib/libtermlib/tparm.c
+++ b/lib/libtermlib/tparm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tparm.c,v 1.5 1997/07/25 20:30:26 mickey Exp $ */
+/* $OpenBSD: tparm.c,v 1.6 1997/12/16 03:10:05 millert Exp $ */
/*
* Copyright (c) 1996 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
@@ -31,7 +31,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: tparm.c,v 1.5 1997/07/25 20:30:26 mickey Exp $";
+static char rcsid[] = "$OpenBSD: tparm.c,v 1.6 1997/12/16 03:10:05 millert Exp $";
#endif
#include <stdio.h>
@@ -57,7 +57,7 @@ static __inline void push __P((int));
static __inline int popnum __P((void));
static __inline char *popstr __P((void));
-static char *_tparm __P((const char *, char *, va_list));
+static char *_tparm __P((const char *, char *, size_t, va_list));
static union {
unsigned int num;
@@ -86,10 +86,15 @@ popstr()
return stackidx > 0 ? stack[--stackidx].str : NULL;
}
+/*
+ * This function is identical to the GNU tparam() but we don't
+ * advertise it as such since it confuses emacs (and perhaps others).
+ */
static char *
-_tparm(str, buf, ap)
+_tparm(str, buf, siz, ap)
const char *str;
char *buf;
+ size_t siz;
va_list ap;
{
int param[10], variable[26];
@@ -138,21 +143,21 @@ _tparm(str, buf, ap)
while (*str) {
if (*str != '%') {
- if (bufp >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp >= buf + siz)
+ return(NULL);
*bufp++ = *str;
}
else {
switch (*++str) {
case '%':
- if (bufp >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp >= buf + siz)
+ return(NULL);
*bufp++ = '%';
break;
case 'd':
sprintf(scratch, "%d", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
break;
@@ -164,8 +169,8 @@ _tparm(str, buf, ap)
sprintf(scratch, "%02d", popnum());
else
sprintf(scratch, "%03d", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
@@ -174,8 +179,8 @@ _tparm(str, buf, ap)
sprintf(scratch, "%02x", popnum());
else
sprintf(scratch, "%03x", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
@@ -184,15 +189,15 @@ _tparm(str, buf, ap)
case '2':
if (*++str == 'd') {
sprintf(scratch, "%2d", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
else if (*str == 'x') {
sprintf(scratch, "%2x", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
@@ -200,27 +205,27 @@ _tparm(str, buf, ap)
case '3':
if (*++str == 'd') {
sprintf(scratch, "%3d", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
else if (*str == 'x') {
sprintf(scratch, "%3x", popnum());
- if (bufp + strlen(scratch) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(scratch) >= buf + siz)
+ return(NULL);
strcpy(bufp, scratch);
bufp += strlen(bufp);
}
break;
case 'c':
- if (bufp >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp >= buf + siz)
+ return(NULL);
*bufp++ = (char)popnum();
break;
case 's':
- if (bufp + strlen(p = popstr()) >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp + strlen(p = popstr()) >= buf + siz)
+ return(NULL);
strcpy(bufp, p);
bufp += strlen(bufp);
break;
@@ -356,13 +361,10 @@ _tparm(str, buf, ap)
str++;
}
- if (bufp >= buf + MAXRETURNSIZE)
- goto overflow;
+ if (bufp >= buf + siz)
+ return(NULL);
*bufp = '\0';
return(buf);
-overflow:
- strcpy(buf, "OVERFLOW!");
- return(buf);
}
char *
@@ -385,7 +387,7 @@ tparm(va_alist)
/* LINTED pointer casts may be troublesome */
va_start(ap, str);
#endif
- p = _tparm(str, buf, ap);
+ p = _tparm(str, buf, sizeof(buf), ap);
/* LINTED expression has no effect */
va_end(ap);
return(p);