summaryrefslogtreecommitdiff
path: root/usr.sbin/tcpdump/savestr.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/tcpdump/savestr.c')
-rw-r--r--usr.sbin/tcpdump/savestr.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/usr.sbin/tcpdump/savestr.c b/usr.sbin/tcpdump/savestr.c
index 17e089e9949..e9850ccb010 100644
--- a/usr.sbin/tcpdump/savestr.c
+++ b/usr.sbin/tcpdump/savestr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: savestr.c,v 1.3 2000/10/03 14:31:59 ho Exp $ */
+/* $OpenBSD: savestr.c,v 1.4 2003/04/02 20:42:22 millert Exp $ */
/*
* Copyright (c) 1997
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/savestr.c,v 1.3 2000/10/03 14:31:59 ho Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/savestr.c,v 1.4 2003/04/02 20:42:22 millert Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -43,23 +43,23 @@ static const char rcsid[] =
char *
savestr(register const char *str)
{
- register u_int size;
+ register size_t size;
register char *p;
static char *strptr = NULL;
- static u_int strsize = 0;
+ static size_t strsize = 0;
size = strlen(str) + 1;
if (size > strsize) {
strsize = 1024;
if (strsize < size)
strsize = size;
- strptr = (char *)malloc(strsize);
+ strptr = strptr ? realloc(strptr, strsize) : malloc(strsize);
if (strptr == NULL) {
- fprintf(stderr, "savestr: malloc\n");
+ fprintf(stderr, "savestr: cannot allocate memory\n");
exit(1);
}
}
- (void)strcpy(strptr, str);
+ (void)strlcpy(strptr, str, size);
p = strptr;
strptr += size;
strsize -= size;