I use swprintf to create a string in a buffer (using a loop by the way).
const int MaxStringLengthPerCharacter = 10 + 1; wchar_t* pTmp = pBuffer; for ( size_t i = 0; i < nNumPlayers ; ++i) { const int nPlayerId = GetPlayer(i); const int nWritten = swprintf(pTmp, MaxStringLengthPerCharacter, TEXT("%d,"), nPlayerId); assert(nWritten >= 0 ); pTmp += nWritten; } *pTaskPlayers = '\0';
If during testing the statement never hits, can I be sure that it will never get into live code? That is, do I need to check if nWritten is <0 and handle this, or can I safely assume that there will be no problems?
Under what circumstances can it return -1? The documentation more or less simply says: "If the function does not work." In one place, I read that he will fail if he cannot match the arguments (i.e. the format string with varargs), but that doesn't bother me.
I also do not worry about buffer overflows in this case - I know that the buffer is large enough.
source share