+2003-05-27 Jakub Jelinek <jakub@redhat.com>
+
+ * stdio-common/vfprintf.c (process_arg, process_string_arg): Use
+ pa_int/pa_u_int instead of pa_short_int, pa_u_short_int and pa_char.
+ * stdio-common/printf-parse.h (union printf_arg): Remove pa_char,
+ pa_short_int, pa_u_short_int and pa_float.
+
+2003-05-26 Jakub Jelinek <jakub@redhat.com>
+
+ * libio/strops.c (_IO_str_init_static): Change into a wrapper around
+ _IO_str_init_static_internal.
+ (_IO_str_init_static_internal): Moved from _IO_str_init_static,
+ change size argument to _IO_size_t, don't limit sprintf to 64M.
+ (_IO_str_init_readonly): Call _IO_str_init_static_internal.
+ * libio/wstrops.c (_IO_wstr_init_static): Change size argument to
+ _IO_size_t, don't limit swprintf to 256M.
+ (_IO_wstr_init_readonly): Remove.
+ * libio/libioP.h (_IO_str_init_static_internal, _IO_wstr_init_static):
+ Adjust prototypes.
+ (_IO_wstr_init_readonly): Remove prototype.
+ * libio/iovsprintf.c (_IO_vsprintf): Use
+ _IO_str_init_static_internal instead of INTUSE(_IO_str_init_static).
+ * libio/iovsscanf.c (_IO_vsscanf): Likewise.
+ * libio/memstream.c (open_memstream): Likewise.
+ * libio/obprintf.c (_IO_obstack_vfprintf): Likewise.
+ * libio/vasprintf.c (_IO_vasprintf): Likewise.
+ * libio/vsnprintf.c (_IO_vsnprintf): Likewise.
+ * stdio-common/tst-sprintf.c (main): Add new test.
+
2003-05-26 Ulrich Drepper <drepper@redhat.com>
* stdio-common/vfprintf.c (vfprintf): Be bug-compatible with some
-/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997-2003 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
#endif
_IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps;
- INTUSE(_IO_str_init_static) (&sf, string, -1, string);
+ _IO_str_init_static_internal (&sf, string, -1, string);
ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &sf._sbf, format, args);
_IO_putc_unlocked ('\0', (_IO_FILE *) &sf._sbf);
return ret;
-/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997-2003 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
#endif
_IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps;
- INTUSE(_IO_str_init_static) (&sf, (char*)string, 0, NULL);
+ _IO_str_init_static_internal (&sf, (char*)string, 0, NULL);
ret = INTUSE(_IO_vfscanf) ((_IO_FILE *) &sf._sbf, format, args, NULL);
return ret;
}
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
/* And the wide character versions. */
-extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, int, wchar_t *));
-extern void _IO_wstr_init_readonly __P ((_IO_FILE *, const char *, int));
+extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *));
extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
extern _IO_off64_t _IO_str_seekoff_internal __P ((_IO_FILE *, _IO_off64_t,
int, int));
extern void _IO_str_init_static_internal __P ((struct _IO_strfile_ *, char *,
- int, char *));
+ _IO_size_t, char *));
extern struct _IO_jump_t _IO_file_jumps_internal attribute_hidden;
extern struct _IO_jump_t _IO_wfile_jumps_internal attribute_hidden;
-/* Copyright (C) 1995,1996,1997,1999,2000,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995-1997,1999,2000,2002,2003 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
return NULL;
_IO_no_init (&new_f->fp._sf._sbf._f, 0, 0, &new_f->wd, &_IO_wmem_jumps);
_IO_JUMPS ((struct _IO_FILE_plus *) &new_f->fp._sf._sbf) = &_IO_mem_jumps;
- INTUSE(_IO_str_init_static) (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
+ _IO_str_init_static_internal (&new_f->fp._sf, buf, _IO_BUFSIZ, buf);
new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF;
new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
/* Print output of stream to given obstack.
- Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1999-2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
assert (size != 0);
}
- INTUSE(_IO_str_init_static) ((struct _IO_strfile_ *) &new_f.ofile,
- obstack_base (obstack),
- size, obstack_next_free (obstack));
+ _IO_str_init_static_internal ((struct _IO_strfile_ *) &new_f.ofile,
+ obstack_base (obstack),
+ size, obstack_next_free (obstack));
/* Now allocate the rest of the current chunk. */
assert (size == (new_f.ofile.file.file._IO_write_end
- new_f.ofile.file.file._IO_write_base));
-/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997-2003 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
#endif
void
-_IO_str_init_static (sf, ptr, size, pstart)
+_IO_str_init_static_internal (sf, ptr, size, pstart)
_IO_strfile *sf;
char *ptr;
- int size;
+ _IO_size_t size;
char *pstart;
{
_IO_FILE *fp = &sf->_sbf._f;
+ char *end;
if (size == 0)
- size = strlen (ptr);
- else if (size < 0)
- {
- /* If size is negative 'the characters are assumed to
- continue indefinitely.' This is kind of messy ... */
- int s;
- size = 512;
- /* Try increasing powers of 2, as long as we don't wrap around. */
- for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; )
- size = s;
- /* Try increasing size as much as we can without wrapping around. */
- for (s = size >> 1; s > 0; s >>= 1)
- {
- if (ptr + size + s > ptr)
- size += s;
- }
- }
- INTUSE(_IO_setb) (fp, ptr, ptr + size, 0);
+ end = __rawmemchr (ptr, '\0');
+ else if ((_IO_size_t) ptr + size > (_IO_size_t) ptr)
+ end = ptr + size;
+ else
+ end = (char *) -1;
+ INTUSE(_IO_setb) (fp, ptr, end, 0);
fp->_IO_write_base = ptr;
fp->_IO_read_base = ptr;
if (pstart)
{
fp->_IO_write_ptr = pstart;
- fp->_IO_write_end = ptr + size;
+ fp->_IO_write_end = end;
fp->_IO_read_end = pstart;
}
else
{
fp->_IO_write_ptr = ptr;
fp->_IO_write_end = ptr;
- fp->_IO_read_end = ptr+size;
+ fp->_IO_read_end = end;
}
/* A null _allocate_buffer function flags the strfile as being static. */
sf->_s._allocate_buffer = (_IO_alloc_type) 0;
}
-INTDEF(_IO_str_init_static)
+
+void
+_IO_str_init_static (sf, ptr, size, pstart)
+ _IO_strfile *sf;
+ char *ptr;
+ int size;
+ char *pstart;
+{
+ return _IO_str_init_static_internal (sf, ptr, size < 0 ? -1 : size, pstart);
+}
void
_IO_str_init_readonly (sf, ptr, size)
const char *ptr;
int size;
{
- INTUSE(_IO_str_init_static) (sf, (char *) ptr, size, NULL);
+ _IO_str_init_static_internal (sf, (char *) ptr, size < 0 ? -1 : size, NULL);
sf->_sbf._f._IO_file_flags |= _IO_NO_WRITES;
}
#endif
_IO_no_init ((_IO_FILE *) &sf._sbf, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf._sbf) = &_IO_str_jumps;
- INTUSE(_IO_str_init_static) (&sf, string, init_string_size, string);
+ _IO_str_init_static_internal (&sf, string, init_string_size, string);
sf._sbf._f._flags &= ~_IO_USER_BUF;
sf._s._allocate_buffer = (_IO_alloc_type) malloc;
sf._s._free_buffer = (_IO_free_type) free;
-/* Copyright (C) 1994,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1994,1997,1999-2003 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
_IO_no_init (&sf.f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
_IO_JUMPS ((struct _IO_FILE_plus *) &sf.f._sbf) = &_IO_strn_jumps;
string[0] = '\0';
- INTUSE(_IO_str_init_static) (&sf.f, string, maxlen - 1, string);
+ _IO_str_init_static_internal (&sf.f, string, maxlen - 1, string);
ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &sf.f._sbf, format, args);
if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf)
-/* Copyright (C) 1993,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993,1997-1999,2001-2003 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
_IO_wstr_init_static (fp, ptr, size, pstart)
_IO_FILE *fp;
wchar_t *ptr;
- int size;
+ _IO_size_t size;
wchar_t *pstart;
{
+ wchar_t *end;
+
if (size == 0)
- size = __wcslen (ptr);
- else if (size < 0)
- {
- /* If size is negative 'the characters are assumed to
- continue indefinitely.' This is kind of messy ... */
- int s;
- size = 512;
- /* Try increasing powers of 2, as long as we don't wrap around. */
- for (; s = 2*size, s > 0 && ptr + s > ptr && s < 0x4000000L; )
- size = s;
- /* Try increasing size as much as we can without wrapping around. */
- for (s = size >> 1; s > 0; s >>= 1)
- {
- if (ptr + size + s > ptr)
- size += s;
- }
- }
- INTUSE(_IO_wsetb) (fp, ptr, ptr + size, 0);
+ end = ptr + __wcslen (ptr);
+ else if ((_IO_size_t) ptr + size * sizeof (wchar_t) > (_IO_size_t) ptr)
+ end = ptr + size;
+ else
+ /* Even for misaligned ptr make sure there is integral number of wide
+ characters. */
+ end = ptr + (-1 - (_IO_size_t) ptr) / sizeof (wchar_t);
+ INTUSE(_IO_wsetb) (fp, ptr, end, 0);
fp->_wide_data->_IO_write_base = ptr;
fp->_wide_data->_IO_read_base = ptr;
if (pstart)
{
fp->_wide_data->_IO_write_ptr = pstart;
- fp->_wide_data->_IO_write_end = ptr + size;
+ fp->_wide_data->_IO_write_end = end;
fp->_wide_data->_IO_read_end = pstart;
}
else
{
fp->_wide_data->_IO_write_ptr = ptr;
fp->_wide_data->_IO_write_end = ptr;
- fp->_wide_data->_IO_read_end = ptr + size;
+ fp->_wide_data->_IO_read_end = end;
}
/* A null _allocate_buffer function flags the strfile as being static. */
(((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0;
}
-void
-_IO_wstr_init_readonly (fp, ptr, size)
- _IO_FILE *fp;
- const char *ptr;
- int size;
-{
- _IO_wstr_init_static (fp, (wchar_t *) ptr, size, NULL);
- fp->_IO_file_flags |= _IO_NO_WRITES;
-}
-
_IO_wint_t
_IO_wstr_overflow (fp, c)
_IO_FILE *fp;
/* The various kinds off arguments that can be passed to printf. */
union printf_arg
{
- unsigned char pa_char;
wchar_t pa_wchar;
- short int pa_short_int;
int pa_int;
long int pa_long_int;
long long int pa_long_long_int;
- unsigned short int pa_u_short_int;
unsigned int pa_u_int;
unsigned long int pa_u_long_int;
unsigned long long int pa_u_long_long_int;
- float pa_float;
double pa_double;
long double pa_long_double;
const char *pa_string;
if (sprintf (buf, "%.0ls", L"foo") != 0
|| strlen (buf) != 0)
{
- puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output\n");
+ puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output");
result = 1;
}
+#define SIZE (1024*70000)
+#define STR(x) #x
+
+ char *dst = malloc (SIZE + 1);
+
+ if (dst == NULL)
+ {
+ puts ("memory allocation failure");
+ result = 1;
+ }
+ else
+ {
+ sprintf (dst, "%*s", SIZE, "");
+ if (strnlen (dst, SIZE + 1) != SIZE)
+ {
+ puts ("sprintf (dst, \"%*s\", " STR(SIZE) ", \"\") did not produce enough output");
+ result = 1;
+ }
+ free (dst);
+ }
+
return result;
}
else \
if (is_long_num) \
signed_number = args_value[fspec->data_arg].pa_long_int; \
- else if (!is_short) \
+ else /* `char' and `short int' will be promoted to `int'. */ \
signed_number = args_value[fspec->data_arg].pa_int; \
- else \
- signed_number = args_value[fspec->data_arg].pa_short_int; \
\
is_negative = signed_number < 0; \
number.word = is_negative ? (- signed_number) : signed_number; \
number.word = args_value[fspec->data_arg].pa_u_long_int; \
else if (is_char) \
number.word = (unsigned char) \
- args_value[fspec->data_arg].pa_char; \
+ args_value[fspec->data_arg].pa_u_int; \
else if (!is_short) \
number.word = args_value[fspec->data_arg].pa_u_int; \
else \
number.word = (unsigned short int) \
- args_value[fspec->data_arg].pa_u_short_int; \
+ args_value[fspec->data_arg].pa_u_int; \
\
LABEL (number): \
if (prec < 0) \
outchar (__btowc ((unsigned char) va_arg (ap, int))); /* Promoted. */ \
else \
outchar (__btowc ((unsigned char) \
- args_value[fspec->data_arg].pa_char)); \
+ args_value[fspec->data_arg].pa_int)); \
if (left) \
PAD (L' '); \
break; \
if (fspec == NULL) \
outchar ((unsigned char) va_arg (ap, int)); /* Promoted. */ \
else \
- outchar ((unsigned char) args_value[fspec->data_arg].pa_char); \
+ outchar ((unsigned char) args_value[fspec->data_arg].pa_int); \
if (left) \
PAD (' '); \
break; \