diff options
author | Zack Weinberg <zackw@panix.com> | 2018-03-07 09:08:49 -0500 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2018-05-31 21:28:17 -0400 |
commit | 99dc7e331834f942d72c017782b8c058414cc70d (patch) | |
tree | 32dc4a6b39da3297e1f6a60f31c38f14fac92e73 /libio/iovsprintf.c | |
parent | 665a5665924b44f5de0938e4c1a077d5bcfee061 (diff) | |
download | glibc-zack/remove-mode-bits.tar.gz |
Use PRINTF_LDBL_IS_DBL instead of __ldbl_is_dbl.zack/remove-mode-bits
After all that prep work, nldbl-compat.c can now use PRINTF_LDBL_IS_DBL
instead of __no_long_double to control the behavior of printf-like
functions; this is the last thing we needed __no_long_double for, so it
can go away entirely.
* stdio-common/vfprintf-internal.c
(__vfprintf_internal, __vfwprintf_internal): Don't use __ldbl_is_dbl.
* sysdeps/generic/math_ldbl_opt.h: Remove __ldbl_is_dbl.
* sysdeps/ieee754/ldbl-opt/math_ldbl_opt.h: Remove __ldbl_is_dbl
and __no_long_double.
* sysdeps/ieee754/ldbl-opt/math_ldbl_opt.c: Remove file.
* sysdeps/ieee754/ldbl-opt/Makefile (routines): Remove math_ldbl_opt.
* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
(__nldbl_cleanup, set_no_long_double, clear_no_long_double): Remove.
(__nldbl___asprintf, __nldbl_dprintf, __nldbl_fprintf)
(__nldbl_fwprintf, __nldbl_printf, __nldbl_sprintf)
(__nldbl_vfprintf, __nldbl___vsprintf, __nldbl_obstack_vprintf)
(__ndlbl_obstack_printf, __nldbl_snprintf, __nldbl_swprintf)
(__nldbl_vasprintf, __nldbl_vdprintf, __nldbl_vfwprintf)
(__nldbl_vprintf, __nldbl_vsnprintf, __ndlbl_vswprintf)
(__nldbl_vwprintf, __nldbl_wprintf):
Directly call the appropriate __v*printf_internal routine, passing
PRINTF_LDBL_IS_DBL. Do not mess with __no_long_double. Normalize
variable names.
(__nldbl___fprintf_chk, __nldbl___fwprintf_chk)
(__nldbl___printf_chk, __nldbl___snprintf_chk)
(__nldbl___sprintf_chk, __nldbl___swprintf_chk)
(__nldbl___vfprintf_chk, __nldbl___vfwprintf_chk)
(__nldbl___vprintf_chk, __nldbl___vsnprintf_chk)
(__nldbl___vsprintf_chk, __nldbl___vswprintf_chk)
(__nldbl___vwprintf_chk, __nldbl___wprintf_chk)
(__nldbl___vasprintf_chk, __nldbl___asprintf_chk)
(__nldbl___vdprintf_chk, __nldbl___dprintf_chk)
(__nldbl___obstack_vprintf_chk, __nldbl___obstack_printf_chk):
Likewise, and also pass PRINTF_FORTIFY when appropriate.
(__nldbl_syslog, __nldbl_vsyslog):
Directly call __vsyslog_internal, passing PRINTF_LDBL_IS_DBL.
(__nldbl_syslog_chk): Likewise, and also pass PRINTF_FORTIFY when
appropriate.
(__nldbl_vsyslog_chk): Likewise, and also pass PRINTF_FORTIFY when
appropriate. Remove libc_hidden_proto and libc_hidden_def.
Diffstat (limited to 'libio/iovsprintf.c')
-rw-r--r-- | libio/iovsprintf.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c index cf4b9973a7..513ca03013 100644 --- a/libio/iovsprintf.c +++ b/libio/iovsprintf.c @@ -27,8 +27,47 @@ #include "libioP.h" #include "strfile.h" +static int __THROW +_IO_str_chk_overflow (FILE *fp, int c) +{ + /* If we get here, the user-supplied buffer would be overrun by + further output. */ + __chk_fail (); +} + +static const struct _IO_jump_t _IO_str_chk_jumps libio_vtable = +{ + JUMP_INIT_DUMMY, + JUMP_INIT(finish, _IO_str_finish), + JUMP_INIT(overflow, _IO_str_chk_overflow), + JUMP_INIT(underflow, _IO_str_underflow), + JUMP_INIT(uflow, _IO_default_uflow), + JUMP_INIT(pbackfail, _IO_str_pbackfail), + JUMP_INIT(xsputn, _IO_default_xsputn), + JUMP_INIT(xsgetn, _IO_default_xsgetn), + JUMP_INIT(seekoff, _IO_str_seekoff), + JUMP_INIT(seekpos, _IO_default_seekpos), + JUMP_INIT(setbuf, _IO_default_setbuf), + JUMP_INIT(sync, _IO_default_sync), + JUMP_INIT(doallocate, _IO_default_doallocate), + JUMP_INIT(read, _IO_default_read), + JUMP_INIT(write, _IO_default_write), + JUMP_INIT(seek, _IO_default_seek), + JUMP_INIT(close, _IO_default_close), + JUMP_INIT(stat, _IO_default_stat), + JUMP_INIT(showmanyc, _IO_default_showmanyc), + JUMP_INIT(imbue, _IO_default_imbue) +}; + +/* This function is called by regular vsprintf with maxlen set to -1, + and by vsprintf_chk with maxlen set to the size of the output + string. In the former case, _IO_str_chk_overflow will never be + called; in the latter case it will crash the program if the buffer + overflows. */ + int -__vsprintf_internal (char *string, const char *format, va_list args, +__vsprintf_internal (char *string, size_t maxlen, + const char *format, va_list args, unsigned int mode_flags) { _IO_strfile sf; @@ -38,17 +77,22 @@ __vsprintf_internal (char *string, const char *format, va_list args, sf._sbf._f._lock = NULL; #endif _IO_no_init (&sf._sbf._f, _IO_USER_LOCK, -1, NULL, NULL); - _IO_JUMPS (&sf._sbf) = &_IO_str_jumps; - _IO_str_init_static_internal (&sf, string, -1, string); + _IO_JUMPS (&sf._sbf) = &_IO_str_chk_jumps; + string[0] = '\0'; + _IO_str_init_static_internal (&sf, string, + (maxlen == -1) ? -1 : maxlen - 1, + string); + ret = __vfprintf_internal (&sf._sbf._f, format, args, mode_flags); - _IO_putc_unlocked ('\0', &sf._sbf._f); + + *sf._sbf._f._IO_write_ptr = '\0'; return ret; } int __vsprintf (char *string, const char *format, va_list args) { - return __vsprintf_internal (string, format, args, 0); + return __vsprintf_internal (string, -1, format, args, 0); } ldbl_strong_alias (__vsprintf, _IO_vsprintf) |