Address review comment about redundant conditions in __bigint_to_stringb() and __bigint_to_stringo() where 'pos < bufflen - 1' was always true since pos starts from bufflen - 2 and breaks when reaching zero.
Fix loop bounds in __pformat_xint() to avoid accessing null terminators by changing 'strlen(tmp_buf)' to 'strlen(tmp_buf)-1'. This fixes %o of a zero int128 from printing '' (nothing) instead of the '0'. Signed-off-by: Peter Damianov <[email protected]> --- mingw-w64-crt/stdio/mingw_pformat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mingw-w64-crt/stdio/mingw_pformat.c b/mingw-w64-crt/stdio/mingw_pformat.c index da8b5d5be..3470c06c5 100644 --- a/mingw-w64-crt/stdio/mingw_pformat.c +++ b/mingw-w64-crt/stdio/mingw_pformat.c @@ -379,8 +379,8 @@ void __bigint_to_stringb(const uint32_t *digits, const uint32_t digitlen, char * if(!pos) break; /* sanity check */ pos--; } - if(pos < bufflen - 1) - memset(buff,'0', pos + 1); + /* Fill any remaining leading positions with zeros */ + memset(buff, '0', pos + 1); buff[bufflen - 1] = '\0'; } @@ -400,8 +400,8 @@ void __bigint_to_stringo(const uint32_t *digits, const uint32_t digitlen, char * pos--; } } - if(pos < bufflen - 1) - memset(buff,'0', pos + 1); + /* Fill any remaining leading positions with zeros */ + memset(buff, '0', pos + 1); buff[bufflen - 1] = '\0'; } #endif /* defined(__ENABLE_PRINTF128) */ @@ -936,7 +936,7 @@ void __pformat_xint( int fmt, __pformat_intarg_t value, __pformat_t *stream ) __bigint_trim_leading_zeroes(tmp_buf,0); memset(buf,0,bufflen); - for(int32_t i = strlen(tmp_buf); i >= 0; i--) + for(int32_t i = strlen(tmp_buf)-1; i >= 0; i--) *p++ = tmp_buf[i]; #else int mask = (fmt == 'o') ? PFORMAT_OMASK : -- 2.47.3 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
