From 92ade58dc2137253a4a80f9d42ecd150455c6638 Mon Sep 17 00:00:00 2001 From: Pavol Marko Date: Sat, 17 Nov 2007 11:38:18 +0000 Subject: [PATCH] vafmt fixes --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40563 --- sourcehook/generate/sourcehook.h | 3 ++- sourcehook/generate/sourcehook.hxx | 7 ++++--- sourcehook/sourcehook.h | 3 ++- sourcehook/test/test2.cpp | 33 ++++++++++++++++++++++++++---- sourcehook/test/testevents.h | 8 ++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/sourcehook/generate/sourcehook.h b/sourcehook/generate/sourcehook.h index 35dbb5f..8f3b03e 100644 --- a/sourcehook/generate/sourcehook.h +++ b/sourcehook/generate/sourcehook.h @@ -1014,7 +1014,8 @@ SourceHook::CallClass *SH_GET_CALLCLASS(T *p) char buf[::SourceHook::STRBUF_LEN]; \ va_list ap; \ va_start(ap, fmt); \ - vsnprintf(buf, sizeof(buf), fmt, ap); \ + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \ + buf[sizeof(buf) - 1] = 0; \ va_end(ap); diff --git a/sourcehook/generate/sourcehook.hxx b/sourcehook/generate/sourcehook.hxx index 8b8b6fc..11b11b1 100755 --- a/sourcehook/generate/sourcehook.hxx +++ b/sourcehook/generate/sourcehook.hxx @@ -1014,7 +1014,8 @@ SourceHook::CallClass *SH_GET_CALLCLASS(T *p) char buf[::SourceHook::STRBUF_LEN]; \ va_list ap; \ va_start(ap, fmt); \ - vsnprintf(buf, sizeof(buf), fmt, ap); \ + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \ + buf[sizeof(buf) - 1] = 0; \ va_end(ap); @[$1,0,$a: @@ -1131,9 +1132,9 @@ SourceHook::CallClass *SH_GET_CALLCLASS(T *p) #define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \ int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \ - fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \ + fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \ bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \ - fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \ + fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \ rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \ SourceHook::ExecutableClass$1 __SoureceHook_FHM_SHCall##hookname(void *ptr); \ void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \ diff --git a/sourcehook/sourcehook.h b/sourcehook/sourcehook.h index 35dbb5f..8f3b03e 100644 --- a/sourcehook/sourcehook.h +++ b/sourcehook/sourcehook.h @@ -1014,7 +1014,8 @@ SourceHook::CallClass *SH_GET_CALLCLASS(T *p) char buf[::SourceHook::STRBUF_LEN]; \ va_list ap; \ va_start(ap, fmt); \ - vsnprintf(buf, sizeof(buf), fmt, ap); \ + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \ + buf[sizeof(buf) - 1] = 0; \ va_end(ap); diff --git a/sourcehook/test/test2.cpp b/sourcehook/test/test2.cpp index 0957e3e..09e7fe7 100644 --- a/sourcehook/test/test2.cpp +++ b/sourcehook/test/test2.cpp @@ -33,8 +33,9 @@ namespace { va_list ap; va_start(ap, fmt); - char buffer[512]; - vsprintf(buffer, fmt, ap); + char buffer[9999]; + vsnprintf(buffer, 9998, fmt, ap); + buffer[9998] = 0; va_end(ap); ADD_STATE(State_Vafmt_Called(1, std::string(buffer))); } @@ -42,8 +43,9 @@ namespace { va_list ap; va_start(ap, fmt); - char buffer[512]; - vsprintf(buffer, fmt, ap); + char buffer[9999]; + vsnprintf(buffer, 9998, fmt, ap); + buffer[9998] = 0; va_end(ap); ADD_STATE(State_Vafmt_Called(2, std::string(buffer))); return 0.0f; @@ -165,6 +167,29 @@ bool TestVafmtAndOverload(std::string &error) new State_Vafmt_PostHandler_Called(2, std::string("Hello BA1LOPAN")), NULL), "Part 3"); + + // Check LARGE stuff + char tmpbuf[501]; + for (int i = 0; i < 500; ++i) + tmpbuf[i] = (i % 10) + '0'; + tmpbuf[500] = 0; + + pGab->Vafmt2("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", + tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, + tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf); + + char refbuf[SourceHook::STRBUF_LEN]; + for (int i = 0; i < (SourceHook::STRBUF_LEN - 1); ++i) + refbuf[i] = (i % 10) + '0'; + refbuf[SourceHook::STRBUF_LEN - 1] = 0; + + CHECK_STATES((&g_States, + new State_Vafmt_PreHandler_Called(2, std::string(refbuf)), + new State_Vafmt_Called(2, std::string(refbuf)), + new State_Vafmt_PostHandler_Called(2, std::string(refbuf)), + NULL + ), "Part 3.1"); + // Part 4 SH_REMOVE_HOOK_ID(h1); SH_REMOVE_HOOK_ID(h2); diff --git a/sourcehook/test/testevents.h b/sourcehook/test/testevents.h index ef7c891..9123469 100644 --- a/sourcehook/test/testevents.h +++ b/sourcehook/test/testevents.h @@ -86,6 +86,14 @@ namespace } } + if (!ok && g_Verbose) + { + std::cout << std::endl << "FAIL: Should be:" << std::endl; + DumpStates(&requiredstates); + std::cout << std::endl << "FAIL: Is:" << std::endl; + DumpStates(sl); + } + for (StateList::iterator iter = requiredstates.begin(); iter != requiredstates.end(); ++iter) delete *iter; for (StateList::iterator iter = sl->begin(); iter != sl->end(); ++iter)