diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-05-27 08:03:32 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-05-27 08:03:32 +0000 |
commit | 40a54e4d8d66e81a2a5dd5de020ae97cd0019b01 (patch) | |
tree | 960b008144bc080d27ae064c70106fa5052d4424 | |
parent | 7661d9f7838cedc4e35bf86b83cd4d27e41c8e4d (diff) | |
download | glibc-40a54e4d8d66e81a2a5dd5de020ae97cd0019b01.tar.gz glibc-40a54e4d8d66e81a2a5dd5de020ae97cd0019b01.tar.xz glibc-40a54e4d8d66e81a2a5dd5de020ae97cd0019b01.zip |
Update.
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.
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | libio/iovsprintf.c | 4 | ||||
-rw-r--r-- | libio/iovsscanf.c | 4 | ||||
-rw-r--r-- | libio/libioP.h | 5 | ||||
-rw-r--r-- | libio/memstream.c | 4 | ||||
-rw-r--r-- | libio/obprintf.c | 8 | ||||
-rw-r--r-- | libio/strops.c | 48 | ||||
-rw-r--r-- | libio/vasprintf.c | 2 | ||||
-rw-r--r-- | libio/vsnprintf.c | 4 | ||||
-rw-r--r-- | libio/wstrops.c | 46 | ||||
-rw-r--r-- | stdio-common/printf-parse.h | 4 | ||||
-rw-r--r-- | stdio-common/tst-sprintf.c | 23 | ||||
-rw-r--r-- | stdio-common/vfprintf.c | 12 |
13 files changed, 108 insertions, 85 deletions
diff --git a/ChangeLog b/ChangeLog index 26d5ae5e36..74fdd218bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +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 diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c index dbaa53f7c8..b26a99b271 100644 --- a/libio/iovsprintf.c +++ b/libio/iovsprintf.c @@ -1,4 +1,4 @@ -/* 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 @@ -42,7 +42,7 @@ _IO_vsprintf (string, format, args) #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; diff --git a/libio/iovsscanf.c b/libio/iovsscanf.c index 1bb475549c..1a965c2d92 100644 --- a/libio/iovsscanf.c +++ b/libio/iovsscanf.c @@ -1,4 +1,4 @@ -/* 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 @@ -41,7 +41,7 @@ _IO_vsscanf (string, format, args) #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; } diff --git a/libio/libioP.h b/libio/libioP.h index ca6535aab0..38daa1daff 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -619,8 +619,7 @@ extern void _IO_str_init_readonly __P ((struct _IO_strfile_ *, const char *, int 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 *)); @@ -710,7 +709,7 @@ extern int _IO_str_pbackfail_internal __P ((_IO_FILE *, int)); 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; diff --git a/libio/memstream.c b/libio/memstream.c index a3ec964237..efc6d83c21 100644 --- a/libio/memstream.c +++ b/libio/memstream.c @@ -1,4 +1,4 @@ -/* 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 @@ -114,7 +114,7 @@ open_memstream (bufloc, sizeloc) 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; diff --git a/libio/obprintf.c b/libio/obprintf.c index aa59145daa..97b5defc35 100644 --- a/libio/obprintf.c +++ b/libio/obprintf.c @@ -1,5 +1,5 @@ /* 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. @@ -153,9 +153,9 @@ _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) 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)); diff --git a/libio/strops.c b/libio/strops.c index d95f33c2e9..8e5ec6d4e9 100644 --- a/libio/strops.c +++ b/libio/strops.c @@ -1,4 +1,4 @@ -/* 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 @@ -63,33 +63,22 @@ #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; @@ -97,19 +86,28 @@ _IO_str_init_static (sf, ptr, size, pstart) 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) @@ -117,7 +115,7 @@ _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; } diff --git a/libio/vasprintf.c b/libio/vasprintf.c index fb7e00675a..4e5b7f4cac 100644 --- a/libio/vasprintf.c +++ b/libio/vasprintf.c @@ -54,7 +54,7 @@ _IO_vasprintf (result_ptr, format, args) #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; diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c index 8a3afc46bd..3057082ea4 100644 --- a/libio/vsnprintf.c +++ b/libio/vsnprintf.c @@ -1,4 +1,4 @@ -/* 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 @@ -126,7 +126,7 @@ _IO_vsnprintf (string, maxlen, format, args) _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) diff --git a/libio/wstrops.c b/libio/wstrops.c index 3c9c4971e8..b180a8f9b6 100644 --- a/libio/wstrops.c +++ b/libio/wstrops.c @@ -1,4 +1,4 @@ -/* 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 @@ -67,28 +67,20 @@ void _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; @@ -96,29 +88,19 @@ _IO_wstr_init_static (fp, ptr, size, pstart) 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; diff --git a/stdio-common/printf-parse.h b/stdio-common/printf-parse.h index eff2816607..ed0dc8bbc8 100644 --- a/stdio-common/printf-parse.h +++ b/stdio-common/printf-parse.h @@ -51,17 +51,13 @@ struct printf_spec /* 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; diff --git a/stdio-common/tst-sprintf.c b/stdio-common/tst-sprintf.c index afbacd9037..b20561ebfd 100644 --- a/stdio-common/tst-sprintf.c +++ b/stdio-common/tst-sprintf.c @@ -11,9 +11,30 @@ main (void) 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; } diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index f8e01b73a1..63440f4b76 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -581,10 +581,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) 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; \ @@ -675,12 +673,12 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) 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) \ @@ -977,7 +975,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) 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; \ @@ -1096,7 +1094,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) 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; \ |