Fix the printf issue for 64 bits. The following case:

printf("%1$s %1$s\n", "test");

would print garbage instead of the second "test". The problem is __find_arguments
and the patch is a backport of two patches from OpenBSD that fix the issue:

Author: tedu <tedu@cvs.openbsd.org>
Date:   Sat Apr 29 23:00:24 2006 +0000

    check mmap for failure.  the helper functions using it return -1, but
    callers do not yet check since printf() for example is not documented
    to return an error.
    some formatting cleanups.
    mostly ok deraadt millert

Author: millert <millert@cvs.openbsd.org>
Date:   Fri May 16 14:28:54 2008 +0000

    C99 says that for each va_copy() there must be a matching va_end().
    Replace the non-portable hackery in __find_arguments() with a union.
    From FreeBSD.

Change-Id: I6ea392ce6fcf4a319ae6a67ec58cc52fe7cbe534
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
This commit is contained in:
Alexander Ivchenko
2014-04-01 17:01:39 +04:00
parent 9c9ef0db91
commit edd7c2ec25
2 changed files with 106 additions and 67 deletions

View File

@@ -297,6 +297,9 @@ TEST(stdio, snprintf_smoke) {
snprintf(buf, sizeof(buf), "a_%g_b", 3.14);
EXPECT_STREQ("a_3.14_b", buf);
snprintf(buf, sizeof(buf), "%1$s %1$s", "print_me_twice");
EXPECT_STREQ("print_me_twice print_me_twice", buf);
}
TEST(stdio, snprintf_d_INT_MAX) {