Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix allocation when handling positional parameters in printf.
  • Loading branch information
Petr Baudis authored and Ulrich Drepper committed Feb 20, 2011
1 parent e23fe25 commit 84a4211
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2011-01-27 Petr Baudis <pasky@suse.cz>
Ulrich Drepper <drepper@gmail.com>

* stdio-common/vfprintf.c (vfprintf): Pass correct newlen
to extend_alloca().
* stdio-common/bug23.c: New file.
* stdio-common/Makefile (tests): Add bug23.

2010-09-28 Andreas Schwab <schwab@redhat.com>
Ulrich Drepper <drepper@gmail.com>

Expand Down
2 changes: 1 addition & 1 deletion stdio-common/Makefile
Expand Up @@ -60,7 +60,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \
tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \
bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \
scanf16 scanf17 tst-setvbuf1 tst-grouping
scanf16 scanf17 tst-setvbuf1 tst-grouping bug23

test-srcs = tst-unbputc tst-printf

Expand Down
21 changes: 21 additions & 0 deletions stdio-common/bug23.c
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>

static char buf[32768];
static const char expected[] = "\
\n\
a\n\
abbcd55%%%%%%%%%%%%%%%%%%%%%%%%%%\n";

static int
do_test (void)
{
snprintf (buf, sizeof (buf),
"\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d"
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
"a", "b", "c", "d", 5);
return strcmp (buf, expected) != 0;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
5 changes: 3 additions & 2 deletions stdio-common/vfprintf.c
@@ -1,4 +1,4 @@
/* Copyright (C) 1991-2008, 2009, 2010 Free Software Foundation, Inc.
/* Copyright (C) 1991-2008, 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -1682,7 +1682,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
{
/* Extend the array of format specifiers. */
struct printf_spec *old = specs;
specs = extend_alloca (specs, nspecs_max, 2 * nspecs_max);
specs = extend_alloca (specs, nspecs_max,
2 * nspecs_max * sizeof (*specs));

/* Copy the old array's elements to the new space. */
memmove (specs, old, nspecs * sizeof (struct printf_spec));
Expand Down

0 comments on commit 84a4211

Please sign in to comment.