Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jonasmr/microprofile
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasmr committed Jan 4, 2019
2 parents 772525d + 61c923e commit 1885531
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions microprofile.cpp
Expand Up @@ -1436,9 +1436,6 @@ void MicroProfileInit()
S.nJsonSettingsPending = 0;
S.nJsonSettingsBufferSize = 0;
S.nWSWasConnected = 0;
S.WSBuf.pBufferAllocation = (char*)MICROPROFILE_ALLOC(MICROPROFILE_WEBSOCKET_BUFFER_SIZE, 8);
S.WSBuf.pBuffer = S.WSBuf.pBufferAllocation + 20;
S.WSBuf.nBufferSize = MICROPROFILE_WEBSOCKET_BUFFER_SIZE - 20;

for(uint32_t i = 0; i < MICROPROFILE_TIMELINE_MAX_TOKENS; ++i)
{
Expand Down Expand Up @@ -6702,25 +6699,26 @@ void MicroProfileWSPrintf(const char* pFmt, ...)
va_start (args, pFmt);

int nRequiredSize = 0;
MP_ASSERT(S.WSBuf.nPut < S.WSBuf.nBufferSize);
MP_ASSERT(S.WSBuf.nPut <= S.WSBuf.nBufferSize);


#ifdef _WIN32
nRequiredSize = (int)vsnprintf_s(0, 0, 0, pFmt, args);
nRequiredSize = (int)_vscprintf(pFmt, args);
#else
nRequiredSize = (int)vsnprintf(0, 0, pFmt, args);
va_list args_copy;
va_copy(args_copy, args);
nRequiredSize = (int)vsnprintf(0, 0, pFmt, args_copy);
va_end(args_copy);
#endif

if(S.WSBuf.nPut + nRequiredSize + 2 > S.WSBuf.nBufferSize)
{
uint32_t nNewSize = MicroProfileMax(S.WSBuf.nPut + 2 * (nRequiredSize + 2 + 20), S.WSBuf.nBufferSize * 3 / 2);
uint32_t nNewSize = MicroProfileMax(S.WSBuf.nPut + 2 * (nRequiredSize + 2 + 20), MicroProfileMax(S.WSBuf.nBufferSize * 3 / 2, (uint32_t)MICROPROFILE_WEBSOCKET_BUFFER_SIZE));
S.WSBuf.pBufferAllocation = (char*)MICROPROFILE_REALLOC(S.WSBuf.pBufferAllocation, nNewSize);
S.WSBuf.pBuffer = S.WSBuf.pBufferAllocation + 20;
S.WSBuf.nBufferSize = nNewSize - 20;
}

va_start (args, pFmt);

uint32_t nSpace = S.WSBuf.nBufferSize - S.WSBuf.nPut - 1;
MP_ASSERT((int)nSpace > nRequiredSize);
char* pPut = &S.WSBuf.pBuffer[S.WSBuf.nPut];
Expand Down

0 comments on commit 1885531

Please sign in to comment.