Undefined Behaviour in PlatformHelpers.h?

Dec 27, 2014 at 1:48 PM
Running cppcheck on my project using DirectXTK, it reports that va_end is never called in void DebugTrace(const char*, ...), which is undefined behaviour.

Should this concern me?

Thanks,
Eric
Coordinator
Dec 27, 2014 at 6:51 PM
Edited Dec 27, 2014 at 7:09 PM
Interesting. It's certainly an easy enough fix, although I've not seen any problems without it at least with MSVC because the only thing it does is set the va_list variable to nullptr.
    inline void DebugTrace( _In_z_ _Printf_format_string_ const char* format, ... )
    {
#ifdef _DEBUG
        va_list args;
        va_start( args, format );

        char buff[1024]={0};
        vsprintf_s( buff, format, args );
        OutputDebugStringA( buff );
        va_end( args ); // <--- added -------------------
#else
        UNREFERENCED_PARAMETER( format );
#endif
    }
Fixed with changeset 39223

If you find any other issues with standard C++11 compliance in the library, do let me know.
Marked as answer by walbourn on 12/27/2014 at 11:58 AM
Dec 27, 2014 at 10:13 PM
The only other things I can see are using memset and c-style casts, which IMO are no big deal.
Coordinator
Dec 28, 2014 at 2:14 AM
Can you post a list of all the files & line numbers with C-style casts?
Dec 28, 2014 at 2:36 PM
SpriteBatch.cpp line 703 seems to be the only one.
Dec 28, 2014 at 2:40 PM
Also something else I think is UB is found in xwbtool.cpp line 470: the third %u is being fed by an int, not an unsigned int.
Coordinator
Dec 28, 2014 at 3:28 PM
Thanks a lot. VC++ /analyze (aka PREFAST) keeps the code pretty clean to begin with, but it doesn't complain about everything CPPCHECK does.

Fixed with changelist 39224
Marked as answer by walbourn on 12/28/2014 at 8:29 AM