diff options
| author | ruki <[email protected]> | 2018-07-07 00:51:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-07-06 23:09:53 +0800 |
| commit | 9235eb49f5dcfab6052e2a5f958024376d318469 (patch) | |
| tree | de3d8d485bb76ea142a3c961bfb3a05244aa50b8 /core/src | |
| parent | abf9cfcf0905b6110fe57930e3a2e756427eff8f (diff) | |
fix tb_vsnprintf bug
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/tbox/src/tbox/libc/stdio/vsnprintf.c | 8 | ||||
| -rw-r--r-- | core/src/tbox/src/tbox/libc/stdio/vswprintf.c | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/core/src/tbox/src/tbox/libc/stdio/vsnprintf.c b/core/src/tbox/src/tbox/libc/stdio/vsnprintf.c index 520bf92d7..7a069f199 100644 --- a/core/src/tbox/src/tbox/libc/stdio/vsnprintf.c +++ b/core/src/tbox/src/tbox/libc/stdio/vsnprintf.c @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright (C) 2009 - 2017, TBOOX Open Source Group. + * Copyright (C) 2009 - 2018, TBOOX Open Source Group. * * @author ruki * @file vsnprintf.c @@ -965,8 +965,9 @@ tb_long_t tb_vsnprintf(tb_char_t* s, tb_size_t n, tb_char_t const* fmt, tb_va_li // check if (!n || !s || !fmt) return 0; + // init start and end pointer tb_char_t* pb = s; - tb_char_t* pe = s + n; + tb_char_t* pe = s + n - 1; #if 0 // pe must be larger than pb @@ -1116,6 +1117,9 @@ tb_long_t tb_vsnprintf(tb_char_t* s, tb_size_t n, tb_char_t const* fmt, tb_va_li } } + // end + if (pb < s + n) *pb = '\0'; + // the trailing null byte doesn't count towards the total return (pb - s); } diff --git a/core/src/tbox/src/tbox/libc/stdio/vswprintf.c b/core/src/tbox/src/tbox/libc/stdio/vswprintf.c index 7712265c1..6e503cf81 100644 --- a/core/src/tbox/src/tbox/libc/stdio/vswprintf.c +++ b/core/src/tbox/src/tbox/libc/stdio/vswprintf.c @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright (C) 2009 - 2017, TBOOX Open Source Group. + * Copyright (C) 2009 - 2018, TBOOX Open Source Group. * * @author ruki * @file vswprintf.c @@ -966,10 +966,12 @@ get_qualifier: */ tb_long_t tb_vswprintf(tb_wchar_t* s, tb_size_t n, tb_wchar_t const* fmt, tb_va_list_t args) { + // check if (!n || !s || !fmt) return 0; + // init start and end pointer tb_wchar_t* pb = s; - tb_wchar_t* pe = s + n; + tb_wchar_t* pe = s + n - 1; #if 0 // pe must be larger than pb @@ -1119,6 +1121,9 @@ tb_long_t tb_vswprintf(tb_wchar_t* s, tb_size_t n, tb_wchar_t const* fmt, tb_va_ } } + // end + if (pb < s + n) *pb = L'\0'; + // the trailing null byte doesn't count towards the total return (pb - s); } |
