1
0
mirror of https://git.code.sf.net/p/mingw-w64/mingw-w64 synced 2025-04-18 17:44:18 +03:00

crt: Avoid memset calls in stdio format functions.

In preparation for building the CRT with -fno-builtin. This allows the compiler
to zero memory without making an actual library call.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
This commit is contained in:
Jacek Caban 2025-03-22 12:52:33 +01:00
parent 7ea592a7ba
commit ecc01089f2
7 changed files with 20 additions and 39 deletions

View File

@ -512,8 +512,7 @@ void __pformat_putchars( const char *s, int count, __pformat_t *stream )
wchar_t w[12], *p;
while( count > 0 )
{
mbstate_t ps;
memset(&ps, 0, sizeof(ps) );
mbstate_t ps = {0};
--count;
p = &w[0];
l = mbrtowc (p, s, strlen (s), &ps);
@ -1175,11 +1174,8 @@ void __pformat_emit_radix_point( __pformat_t *stream )
/* Radix point initialisation not yet completed;
* establish a multibyte to `wchar_t' converter...
*/
int len; wchar_t rpchr; mbstate_t state;
/* Initialise the conversion state...
*/
memset( &state, 0, sizeof( state ) );
int len; wchar_t rpchr;
mbstate_t state = {0};
/* Fetch and convert the localised radix point representation...
*/
@ -1203,11 +1199,8 @@ void __pformat_emit_radix_point( __pformat_t *stream )
#ifdef __BUILD_WIDEAPI
__pformat_putc (stream->rpchr, stream);
#else
int len; char buf[len = stream->rplen]; mbstate_t state;
/* Initialise the conversion state...
*/
memset( &state, 0, sizeof( state ) );
int len; char buf[len = stream->rplen];
mbstate_t state = {0};
/* Convert the `wchar_t' representation to multibyte...
*/
@ -3123,8 +3116,8 @@ __pformat (int flags, void *dest, int max, const APICHAR *fmt, va_list argv)
if (state == PFORMAT_INIT)
{
stream.flags |= PFORMAT_GROUPED; /* $$$$ */
int len; wchar_t rpchr; mbstate_t cstate;
memset (&cstate, 0, sizeof(state));
int len; wchar_t rpchr;
mbstate_t cstate = {0};
if ((len = mbrtowc( &rpchr, localeconv()->thousands_sep, 16, &cstate)) > 0)
stream.thousands_chr = rpchr;
stream.thousands_chr_len = len;

View File

@ -307,7 +307,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
char seen_dot, seen_exp, is_neg, not_in;
char *tmp_wbuf_ptr, buf[MB_LEN_MAX];
const char *lc_decimal_point, *lc_thousands_sep;
mbstate_t state, cstate;
mbstate_t state = {0}, cstate;
union {
unsigned long long ull;
unsigned long ul;
@ -323,8 +323,6 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
return EOF;
}
memset (&state, 0, sizeof (state));
lc_decimal_point = localeconv()->decimal_point;
lc_thousands_sep = localeconv()->thousands_sep;
if (lc_thousands_sep != NULL && *lc_thousands_sep == 0)
@ -682,7 +680,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
if ((c = in_ch (s, &read_in)) == EOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&cstate, 0, sizeof (cstate));
cstate = (mbstate_t){0};
do
{
@ -854,7 +852,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
if ((c = in_ch (s, &read_in)) == EOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&cstate, 0, sizeof (cstate));
cstate = (mbstate_t){0};
do
{
@ -1459,7 +1457,7 @@ __mingw_sformat (_IFP *s, const char *format, va_list argp)
if ((c = in_ch (s, &read_in)) == EOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&cstate, 0, sizeof (cstate));
cstate = (mbstate_t){0};
do
{

View File

@ -332,10 +332,10 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
return EOF;
}
memset (&state, 0, sizeof(state));
state = (mbstate_t){0};
clen = mbrtowc( &wc, localeconv()->decimal_point, 16, &state);
lc_decimal_point = (clen > 0 ? wc : '.');
memset( &state, 0, sizeof( state ) );
state = (mbstate_t){0};
clen = mbrtowc( &wc, localeconv()->thousands_sep, 16, &state);
lc_thousands_sep = (clen > 0 ? wc : 0);
@ -596,7 +596,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
if ((c = in_ch (s, &read_in)) == WEOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&state, 0, sizeof (state));
state = (mbstate_t){0};
do
{
@ -744,7 +744,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
if ((c = in_ch (s, &read_in)) == WEOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&state, 0, sizeof (state));
state = (mbstate_t){0};
do
{
@ -1459,7 +1459,7 @@ __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp)
if ((c = in_ch (s, &read_in)) == WEOF)
return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf);
memset (&state, 0, sizeof (state));
state = (mbstate_t){0};
do
{

View File

@ -7,8 +7,6 @@
int
__mingw_vfscanf (FILE *s, const char *format, va_list argp)
{
_IFP ifp;
memset (&ifp, 0, sizeof (_IFP));
ifp.fp = s;
_IFP ifp = { .fp = s };
return __mingw_sformat (&ifp, format, argp);
}

View File

@ -7,8 +7,6 @@
int
__mingw_vfwscanf (FILE *s, const wchar_t *format, va_list argp)
{
_IFPW ifp;
memset (&ifp, 0, sizeof (_IFPW));
ifp.fp = s;
_IFPW ifp = { .fp = s };
return __mingw_swformat (&ifp, format, argp);
}

View File

@ -7,9 +7,6 @@
int
__mingw_vsscanf (const char *s, const char *format, va_list argp)
{
_IFP ifp;
memset (&ifp, 0, sizeof (_IFP));
ifp.str = s;
ifp.is_string = 1;
_IFP ifp = { .str = s, .is_string = 1 };
return __mingw_sformat (&ifp, format, argp);
}

View File

@ -7,9 +7,6 @@
int
__mingw_vswscanf (const wchar_t *s, const wchar_t *format, va_list argp)
{
_IFPW ifp;
memset (&ifp, 0, sizeof (_IFPW));
ifp.str = s;
ifp.is_string = 1;
_IFPW ifp = { .str = s, .is_string = 1 };
return __mingw_swformat (&ifp, format, argp);
}