Skip to content

Commit

Permalink
Merge 84a8bb6 into 5432cb8
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Apr 6, 2023
2 parents 5432cb8 + 84a8bb6 commit 2b19bb8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions include/internal/iutest_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2011-2021, Takazumi Shirayanagi\n
* Copyright (C) 2011-2023, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -140,12 +140,13 @@ inline int iu_vsnprintf(char* dst, size_t size, const char* format, va_list va)
{
char buffer[4096] = {0};
char* write_buffer = dst != NULL && size >= 4096 ? dst : buffer;
const int ret = vsprintf(write_buffer, format, va);
const int ret = vsnprintf(write_buffer, size, format, va);
if( dst != NULL )
{
const size_t length = static_cast<size_t>(ret);
const size_t write = (size <= length) ? size - 1 : length;
if( write_buffer == buffer ) {
if( write_buffer == buffer )
{
strncpy(dst, buffer, write);
}
dst[write] = '\0';
Expand Down
5 changes: 2 additions & 3 deletions include/internal/iutest_string_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2011-2021, Takazumi Shirayanagi\n
* Copyright (C) 2011-2023, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -230,8 +230,7 @@ IUTEST_PRAGMA_WARN_DISABLE_FORMAT_NONLITERAL()
static int vastring(E* dst, const E* fmt, va_list va);
static int vastring(char* dst, size_t len, const char* fmt, va_list va) IUTEST_ATTRIBUTE_FORMAT_PRINTF(3, 0)
{
(void)len;
return vsprintf(dst, fmt, va);
return vsnprintf(dst, len, fmt, va);
}
static int vastring(wchar_t* dst, size_t len, const wchar_t* fmt, va_list va)
{
Expand Down
4 changes: 2 additions & 2 deletions test/assertion_only_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2012-2022, Takazumi Shirayanagi\n
* Copyright (C) 2012-2023, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ void test_vprintf(const char* fmt, va_list va)
{
IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
char buf[4096];
vsprintf(buf, fmt, va);
vsnprintf(buf, sizeof(buf), fmt, va);
s_outstream << buf;
IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
}
Expand Down
4 changes: 2 additions & 2 deletions test/logger_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2014-2020, Takazumi Shirayanagi\n
* Copyright (C) 2014-2023, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand All @@ -31,7 +31,7 @@ IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
char buf[4096] = { 0 };
va_list va2;
iu_va_copy(va2, va);
vsprintf(buf, fmt, va2);
vsnprintf(buf, sizeof(buf), fmt, va2);
va_end(va2);
m_log += buf;
::iutest::detail::iuConsole::nl_voutput(fmt, va);
Expand Down

0 comments on commit 2b19bb8

Please sign in to comment.