Add templated helper class to promote type-safety#965
Conversation
extensions/sdktools/inputnatives.cpp
Outdated
|
|
||
| bool ret; | ||
| g_pAcceptInput->Execute(vstk, &ret); | ||
| MemWriter<void*, const char*, CBaseEntity*, CBaseEntity*, decltype(g_Variant_t), int> vstk(pDest, inputname, pActivator, pCaller, g_Variant_t, params[5]); |
There was a problem hiding this comment.
in-case anyone's curious, this decltype(g_Variant_t) should be okay since it's a global char[] (not char*)
char test[32];
std::cout << sizeof(test) << std::endl; //32
std::cout << sizeof(decltype(test)) << std::endl; //32
KyleSanderson
left a comment
There was a problem hiding this comment.
This is nice; but there's a multitude of style defects and I'd like to know why we're calling malloc when we can hopefully use stack storage instead.
|
Things should be a-okay now. Buffer is now statically allocated, renamed it per the suggestion to |
KyleSanderson
left a comment
There was a problem hiding this comment.
The style is still wildly inconsistent 😢
|
This is a really nice quality-of-life improvement. Obviously it looks sane and should behave sanely, but has this been tested in-game with any of these calls? |
|
@asherkin no, but I’ve ensured through type-punning by hand that the buffer format is okay. I can do game testing as well to ensure |
KyleSanderson
left a comment
There was a problem hiding this comment.
Please test in-game to ensure this doesn't break anything. Beyond that fundamentally it's an improvement; thanks for this.
|
Everything seems to function just as before. Ran through |
|
@asherkin nope! |
Along with some type safety checks to ensure everything is kosher, this also technically fixes us relying on UB punning.