From 6999a6bc5c00df4b2d6247b1dff1081175ea6bec Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Sun, 28 May 2006 00:51:16 +0000 Subject: [PATCH] fixing two hiden bug in reactos, null termante the string right at end, code tested in vs, but it seam no affact on wine test mscvrt printf test. What hell is the snprintf function call to ?? svn path=/trunk/; revision=22081 --- reactos/lib/rtl/sprintf.c | 16 +++++++++++++++- reactos/lib/rtl/swprintf.c | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/reactos/lib/rtl/sprintf.c b/reactos/lib/rtl/sprintf.c index c8b1e6af911..37fb4c20c70 100644 --- a/reactos/lib/rtl/sprintf.c +++ b/reactos/lib/rtl/sprintf.c @@ -253,6 +253,8 @@ int _vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args) number of chars for from string */ int qualifier; /* 'h', 'l', 'L', 'I' or 'w' for integer fields */ + /* clear the string buffer with zero so we do not need NULL terment it at end */ + str = buf; end = buf + cnt - 1; if (end < buf - 1) { @@ -501,8 +503,20 @@ int _vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args) if (str <= end) *str = '\0'; else if (cnt > 0) + { /* don't write out a null byte if the buf size is zero */ - *end = '\0'; + //*end = '\0'; + if (str-buf >=cnt ) + { + *end = '\0'; + } + else + { + end++; + *end = '\0'; + } + + } return str-buf; } diff --git a/reactos/lib/rtl/swprintf.c b/reactos/lib/rtl/swprintf.c index b8c2d2ba670..f14d6590d89 100644 --- a/reactos/lib/rtl/swprintf.c +++ b/reactos/lib/rtl/swprintf.c @@ -500,9 +500,21 @@ int _vsnwprintf(wchar_t *buf, size_t cnt, const wchar_t *fmt, va_list args) } if (str <= end) *str = L'\0'; - else if (cnt > 0) + else if (cnt > 0) + { /* don't write out a null byte if the buf size is zero */ - *end = L'\0'; + //*end = '\0'; + if (str-buf >=cnt ) + { + *end = L'\0'; + } + else + { + end++; + *end = L'\0'; + } + + } return str-buf; }