int vsnprintfTest(void) { int len; int status = TC_PASS; char buffer[100]; /* * The string size may be handled in a non-standard manner. * If a negative value is supplied for the string size, it is converted * to 0x7fffffff--maximum integer size. Since there is insufficient * memory to test a string of that length, we just check that the string * was fully written so that we can exercise the code path. */ buffer[0] = '\0'; len = tvsnprintf(buffer, (size_t)(-4), "%x", DEADBEEF); if (len != strlen(DEADBEEF_LHEX_STR)) { TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", strlen(DEADBEEF_LHEX_STR), len); status = TC_FAIL; } if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", DEADBEEF_LHEX_STR, buffer); status = TC_FAIL; } /*******************/ buffer[0] = '\0'; len = tvsnprintf(buffer, 0, "%x", DEADBEEF); if (len != strlen(DEADBEEF_LHEX_STR)) { TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", strlen(DEADBEEF_LHEX_STR), len); status = TC_FAIL; } if (strcmp(buffer, "") != 0) { TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", "", buffer); status = TC_FAIL; } /*******************/ len = tvsnprintf(buffer, 4, "%x", DEADBEEF); if (len != strlen(DEADBEEF_LHEX_STR)) { TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", strlen(DEADBEEF_LHEX_STR), len); status = TC_FAIL; } if (strcmp(buffer, "dea") != 0) { TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", "dea", buffer); status = TC_FAIL; } return status; }
VOID LONG_DB_QUERY::Parse(const CHAR* pTemplate,...) { va_list argptr; va_start(argptr, pTemplate); int nchars = tvsnprintf((char*)m_SqlStr, MAX_LONG_SQL_LENGTH, pTemplate, argptr ); va_end(argptr); if (nchars == -1 || nchars > MAX_LONG_SQL_LENGTH ) { Assert(FALSE); return; } }
int vsnprintfTest(void) { int len; int status = TC_PASS; char buffer[100]; /*******************/ buffer[0] = '\0'; len = tvsnprintf(buffer, 0, "%x", DEADBEEF); if (len != strlen(DEADBEEF_LHEX_STR)) { TC_ERROR("vsnprintf(%%x). Expected return value %zu, not %d\n", strlen(DEADBEEF_LHEX_STR), len); status = TC_FAIL; } if (strcmp(buffer, "") != 0) { TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", "", buffer); status = TC_FAIL; } /*******************/ len = tvsnprintf(buffer, 4, "%x", DEADBEEF); if (len != strlen(DEADBEEF_LHEX_STR)) { TC_ERROR("vsnprintf(%%x). Expected return value %zu, not %d\n", strlen(DEADBEEF_LHEX_STR), len); status = TC_FAIL; } if (strcmp(buffer, "dea") != 0) { TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", "dea", buffer); status = TC_FAIL; } return status; }
void __assertspecial__(const char* file, uint line, const char* myFunction, const char* myException, const char* msg, ...) { char strLog[MAX_SHOWMESSAGE_LENGTH] = {0}; va_list argp; va_start(argp, msg); char buf[MAX_SHOWMESSAGE_LENGTH] = {0}; int nCount = tvsnprintf(buf, MAX_SHOWMESSAGE_LENGTH, msg, argp); va_end(argp); #ifdef _WIN32 tsnprintf(strLog, sizeof(strLog), "[%s][%d][%s][%s]\n[%s]", file, line, myFunction, myException, buf); #endif #ifdef _LINUX64 tsnprintf(strLog, sizeof(strLog), "[%s][%d][%s][%s]\n[%s]\n", file, line, myFunction, myException, buf); #endif __show__(strLog); }