Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

printf("%zi\n", (ssize_t)-1) failure



NetBSD-4, -5 and -current fail with printf("%zi\n", (ssize_t)-1);
On i386 the result is 4294967295.
On amd64 -5 it works and prints -1.

Test case

#include <sys/types.h>
#include <stdio.h>
 
int main(int argc, char **argv)
{
        return printf("%zi\n", (ssize_t)-1);
}

Proposed patch, tested on -current i386

Index: vfwprintf.c
===================================================================
RCS file: /cvsroot/src/lib/libc/stdio/vfwprintf.c,v
retrieving revision 1.14
diff -u -p -r1.14 vfwprintf.c
--- vfwprintf.c 30 Jan 2009 23:46:59 -0000      1.14
+++ vfwprintf.c 19 Feb 2009 12:30:14 -0000
@@ -98,6 +98,7 @@ union arg {
        long long longlongarg;
        unsigned long long ulonglongarg;
        ptrdiff_t ptrdiffarg;
+       ssize_t ssizearg;
        size_t  sizearg;
        intmax_t intmaxarg;
        uintmax_t uintmaxarg;
@@ -125,7 +126,7 @@ union arg {
 enum typeid {
        T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT,
        T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
-       T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
+       T_PTRDIFFT, TP_PTRDIFFT, T_SSIZET, T_SIZET, TP_SIZET,
        T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
        T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR
 };
@@ -756,7 +757,7 @@ WDECL(__vf,printf_unlocked)(FILE *fp, co
 #define        INTMAX_SIZE     (INTMAXT|SIZET|PTRDIFFT|LLONGINT)
 #define SJARG() \
        (flags&INTMAXT ? GETARG(intmax_t) : \
-           flags&SIZET ? (intmax_t)GETARG(size_t) : \
+           flags&SIZET ? (intmax_t)GETARG(ssize_t) : \
            flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
            (intmax_t)GETARG(long long))
 #define        UJARG() \
@@ -1571,7 +1572,7 @@ __find_arguments(const CHAR_T *fmt0, va_
                if (flags & INTMAXT)  \
                        ADDTYPE(T_INTMAXT); \
                else if (flags & SIZET)  \
-                       ADDTYPE(T_SIZET); \
+                       ADDTYPE(T_SSIZET); \
                else if (flags & PTRDIFFT) \
                        ADDTYPE(T_PTRDIFFT); \
                else if (flags & LLONGINT) \
@@ -1838,6 +1839,9 @@ done:
                    case TP_PTRDIFFT:
                        (*argtable) [n].pptrdiffarg = va_arg (ap, ptrdiff_t
*);
                        break;
+                   case T_SSIZET:
+                       (*argtable) [n].ssizearg = va_arg (ap, ssize_t);
+                       break;
                    case T_SIZET:
                        (*argtable) [n].sizearg = va_arg (ap, size_t);
                        break;


Comments? OK to commit?

Thanks

Roy


Home | Main Index | Thread Index | Old Index