1.1 --- a/sourcehook/generate/sourcehook.h Sat Nov 10 11:01:42 2007 +0000
1.2 +++ b/sourcehook/generate/sourcehook.h Sat Nov 17 11:38:18 2007 +0000
1.3 @@ -1014,7 +1014,8 @@
1.4 char buf[::SourceHook::STRBUF_LEN]; \
1.5 va_list ap; \
1.6 va_start(ap, fmt); \
1.7 - vsnprintf(buf, sizeof(buf), fmt, ap); \
1.8 + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
1.9 + buf[sizeof(buf) - 1] = 0; \
1.10 va_end(ap);
1.11
1.12
2.1 --- a/sourcehook/generate/sourcehook.hxx Sat Nov 10 11:01:42 2007 +0000
2.2 +++ b/sourcehook/generate/sourcehook.hxx Sat Nov 17 11:38:18 2007 +0000
2.3 @@ -1014,7 +1014,8 @@
2.4 char buf[::SourceHook::STRBUF_LEN]; \
2.5 va_list ap; \
2.6 va_start(ap, fmt); \
2.7 - vsnprintf(buf, sizeof(buf), fmt, ap); \
2.8 + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
2.9 + buf[sizeof(buf) - 1] = 0; \
2.10 va_end(ap);
2.11
2.12 @[$1,0,$a:
2.13 @@ -1131,9 +1132,9 @@
2.14
2.15 #define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \
2.16 int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
2.17 - fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
2.18 + fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \
2.19 bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
2.20 - fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
2.21 + fastdelegate::FastDelegate$1<@[$2,1,$1:param$2, @]rettype> handler); \
2.22 rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \
2.23 SourceHook::ExecutableClass$1<SourceHook::EmptyClass, rettype(::SourceHook::EmptyClass::*)(@[$2,1,$1|, :param$2@]), rettype@[$2,1,$1:, param$2@]> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
2.24 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \
3.1 --- a/sourcehook/sourcehook.h Sat Nov 10 11:01:42 2007 +0000
3.2 +++ b/sourcehook/sourcehook.h Sat Nov 17 11:38:18 2007 +0000
3.3 @@ -1014,7 +1014,8 @@
3.4 char buf[::SourceHook::STRBUF_LEN]; \
3.5 va_list ap; \
3.6 va_start(ap, fmt); \
3.7 - vsnprintf(buf, sizeof(buf), fmt, ap); \
3.8 + vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
3.9 + buf[sizeof(buf) - 1] = 0; \
3.10 va_end(ap);
3.11
3.12
4.1 --- a/sourcehook/test/test2.cpp Sat Nov 10 11:01:42 2007 +0000
4.2 +++ b/sourcehook/test/test2.cpp Sat Nov 17 11:38:18 2007 +0000
4.3 @@ -33,8 +33,9 @@
4.4 {
4.5 va_list ap;
4.6 va_start(ap, fmt);
4.7 - char buffer[512];
4.8 - vsprintf(buffer, fmt, ap);
4.9 + char buffer[9999];
4.10 + vsnprintf(buffer, 9998, fmt, ap);
4.11 + buffer[9998] = 0;
4.12 va_end(ap);
4.13 ADD_STATE(State_Vafmt_Called(1, std::string(buffer)));
4.14 }
4.15 @@ -42,8 +43,9 @@
4.16 {
4.17 va_list ap;
4.18 va_start(ap, fmt);
4.19 - char buffer[512];
4.20 - vsprintf(buffer, fmt, ap);
4.21 + char buffer[9999];
4.22 + vsnprintf(buffer, 9998, fmt, ap);
4.23 + buffer[9998] = 0;
4.24 va_end(ap);
4.25 ADD_STATE(State_Vafmt_Called(2, std::string(buffer)));
4.26 return 0.0f;
4.27 @@ -165,6 +167,29 @@
4.28 new State_Vafmt_PostHandler_Called(2, std::string("Hello BA1LOPAN")),
4.29 NULL), "Part 3");
4.30
4.31 +
4.32 + // Check LARGE stuff
4.33 + char tmpbuf[501];
4.34 + for (int i = 0; i < 500; ++i)
4.35 + tmpbuf[i] = (i % 10) + '0';
4.36 + tmpbuf[500] = 0;
4.37 +
4.38 + pGab->Vafmt2("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
4.39 + tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf,
4.40 + tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf);
4.41 +
4.42 + char refbuf[SourceHook::STRBUF_LEN];
4.43 + for (int i = 0; i < (SourceHook::STRBUF_LEN - 1); ++i)
4.44 + refbuf[i] = (i % 10) + '0';
4.45 + refbuf[SourceHook::STRBUF_LEN - 1] = 0;
4.46 +
4.47 + CHECK_STATES((&g_States,
4.48 + new State_Vafmt_PreHandler_Called(2, std::string(refbuf)),
4.49 + new State_Vafmt_Called(2, std::string(refbuf)),
4.50 + new State_Vafmt_PostHandler_Called(2, std::string(refbuf)),
4.51 + NULL
4.52 + ), "Part 3.1");
4.53 +
4.54 // Part 4
4.55 SH_REMOVE_HOOK_ID(h1);
4.56 SH_REMOVE_HOOK_ID(h2);
5.1 --- a/sourcehook/test/testevents.h Sat Nov 10 11:01:42 2007 +0000
5.2 +++ b/sourcehook/test/testevents.h Sat Nov 17 11:38:18 2007 +0000
5.3 @@ -86,6 +86,14 @@
5.4 }
5.5 }
5.6
5.7 + if (!ok && g_Verbose)
5.8 + {
5.9 + std::cout << std::endl << "FAIL: Should be:" << std::endl;
5.10 + DumpStates(&requiredstates);
5.11 + std::cout << std::endl << "FAIL: Is:" << std::endl;
5.12 + DumpStates(sl);
5.13 + }
5.14 +
5.15 for (StateList::iterator iter = requiredstates.begin(); iter != requiredstates.end(); ++iter)
5.16 delete *iter;
5.17 for (StateList::iterator iter = sl->begin(); iter != sl->end(); ++iter)