Skip to content

Commit

Permalink
Fixed regression caused by switching to the "safe" vsnprintf().
Browse files Browse the repository at this point in the history
  • Loading branch information
tylov committed Oct 21, 2024
1 parent d606b47 commit fe287e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ if (UNIX)
endif()


#[[
include(CTest)

if (BUILD_TESTING)
file(GLOB examples misc/examples/*.c)
foreach (file IN LISTS examples)
get_filename_component(name "${file}" NAME_WE)
add_executable(${name} ${file})
#target_compile_options(${name} PRIVATE "-pthread")
target_compile_options(${name} PRIVATE "-DSTC_STATIC")
if (CMAKE_THREAD_LIBS_INIT)
target_link_libraries(${name} PRIVATE "${CMAKE_THREAD_LIBS_INIT}")
Expand All @@ -42,4 +40,4 @@ if (BUILD_TESTING)
# add_test(NAME ${name} COMMAND ${name})
# endforeach()
endif()
]]

2 changes: 1 addition & 1 deletion include/c11/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ FMT_DEF void _fmt_sprint(fmt_stream* ss, const char* fmt, ...) {
ss->cap = ss->len + ss->cap/2;
ss->data = (char*)realloc(ss->data, (size_t)ss->cap + 1U);
}
vsnprintf(ss->data + pos, (size_t)n, fmt, args2);
vsnprintf(ss->data + pos, (size_t)n+1, fmt, args2);
done2: va_end(args2);
done1: va_end(args);
}
Expand Down
2 changes: 1 addition & 1 deletion include/stc/priv/cstr_prv.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static isize cstr_vfmt(cstr* self, isize start, const char* fmt, va_list args) {
va_list args2;
va_copy(args2, args);
const int n = vsnprintf(NULL, 0ULL, fmt, args);
vsnprintf(cstr_reserve(self, start + n) + start, (size_t)n, fmt, args2);
vsnprintf(cstr_reserve(self, start + n) + start, (size_t)n+1, fmt, args2);
va_end(args2);
_cstr_set_size(self, start + n);
return n;
Expand Down
13 changes: 6 additions & 7 deletions misc/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# run tests

cd $(dirname $(realpath $0))

if [ -z "$1" ]; then
tcc -Wall -I../../include *_test.c main.c -run
else
cc=gcc
if [ ! -z "$1" ]; then
cc=$1
$cc -O2 -Wall -I../../include *_test.c main.c -o tests.exe
./tests.exe
rm -f ./tests.exe
fi

$cc -O2 -Wall -I../../include *_test.c main.c -o tests.exe -lstc
./tests.exe
rm -f ./tests.exe

0 comments on commit fe287e0

Please sign in to comment.