summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfwprintf.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-04-22 11:35:12 +0000
committertjr <tjr@FreeBSD.org>2004-04-22 11:35:12 +0000
commit2d6eafdb97fda1bbf2b528e6282360c164bcb57a (patch)
treeb40d4b9124f86cade2e9682cc1d4306aed4ee47c /lib/libc/stdio/vfwprintf.c
parente3daaa170bb35d24c6d9c98f6b14163bba660f56 (diff)
downloadFreeBSD-src-2d6eafdb97fda1bbf2b528e6282360c164bcb57a.zip
FreeBSD-src-2d6eafdb97fda1bbf2b528e6282360c164bcb57a.tar.gz
Use the correct size to allocate, copy and clear argument type tables
after their change from an array of char to an array of enum. This fixes problems that occurred when using positional arguments in format strings, particularly with more than STATIC_ARG_TBL_SIZE (8) of them. PR: 65841 Submitted by: Steven Smith (mostly)
Diffstat (limited to 'lib/libc/stdio/vfwprintf.c')
-rw-r--r--lib/libc/stdio/vfwprintf.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c
index 9a34ff0..afecc97 100644
--- a/lib/libc/stdio/vfwprintf.c
+++ b/lib/libc/stdio/vfwprintf.c
@@ -1317,7 +1317,8 @@ __find_arguments (const wchar_t *fmt0, va_list ap, union arg **argtable)
tablesize = STATIC_ARG_TBL_SIZE;
tablemax = 0;
nextarg = 1;
- memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
+ for (n = 0; n < STATIC_ARG_TBL_SIZE; n++)
+ typetable[n] = T_UNUSED;
/*
* Scan the format for conversions (`%' character).
@@ -1586,19 +1587,21 @@ __grow_type_table (int nextarg, enum typeid **typetable, int *tablesize)
enum typeid *const oldtable = *typetable;
const int oldsize = *tablesize;
enum typeid *newtable;
- int newsize = oldsize * 2;
+ int n, newsize = oldsize * 2;
if (newsize < nextarg + 1)
newsize = nextarg + 1;
if (oldsize == STATIC_ARG_TBL_SIZE) {
- if ((newtable = malloc(newsize)) == NULL)
+ if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL)
abort(); /* XXX handle better */
- bcopy(oldtable, newtable, oldsize);
+ bcopy(oldtable, newtable, oldsize * sizeof(enum typeid));
} else {
- if ((newtable = reallocf(oldtable, newsize)) == NULL)
+ newtable = reallocf(oldtable, newsize * sizeof(enum typeid));
+ if (newtable == NULL)
abort(); /* XXX handle better */
}
- memset(&newtable[oldsize], T_UNUSED, newsize - oldsize);
+ for (n = oldsize; n < newsize; n++)
+ newtable[n] = T_UNUSED;
*typetable = newtable;
*tablesize = newsize;
OpenPOWER on IntegriCloud