ref: f6fe4ddeaa1a4751b3f7d58480be824b4fc522fe
parent: 6fea084a42413b295abde288ea533d99ee71b75b
author: Martin Storsjö <[email protected]>
date: Sun Jan 26 09:43:30 EST 2014
Use WelsSnprintf instead of SNPRINTF
--- a/codec/common/crt_util_safe_x.h
+++ b/codec/common/crt_util_safe_x.h
@@ -420,7 +420,6 @@
#if defined(WIN32) && defined(_MSC_VER)
#if _MSC_VER >= 1500 // VS2008
-#define SNPRINTF _snprintf_s
#define LOCALTIME localtime_s
#define FTIME _ftime_s
#define STRNCPY strncpy_s
@@ -428,7 +427,6 @@
#define STRNLEN strnlen_s
#define VSPRINTF vsprintf_s
#else // mainly for VC6
-#define SNPRINTF _snprintf
#define LOCALTIME localtime
#define FTIME _ftime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
@@ -439,7 +437,6 @@
#else//__GNUC__
-#define SNPRINTF snprintf
#define LOCALTIME localtime
#define STRNCPY wels_strncpy_s // override s.t.r.n.c.p.y here for safe
#define STRCAT wels_strcat_s // override s.t.r.c.a.t here for safe
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -327,11 +327,7 @@
pDumpRecFile = WelsFopen (kpFileName, "ab");
else {
str_t sDependencyRecFileName[16] = {0};
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
- SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
-#else
- SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
-#endif//WIN32..
+ WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (sDependencyRecFileName, "ab");
}
if (NULL != pDumpRecFile)
@@ -341,11 +337,7 @@
pDumpRecFile = WelsFopen (kpFileName, "wb");
} else {
str_t sDependencyRecFileName[16] = {0};
-#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1500) // vs2008
- SNPRINTF (sDependencyRecFileName, 16, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
-#else
- SNPRINTF (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
-#endif//WIN32..
+ WelsSnprintf (sDependencyRecFileName, 16, "rec%d.yuv", kiDid); // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (sDependencyRecFileName, "wb");
}
bDependencyRecFlag[kiDid] = true;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2085,19 +2085,8 @@
if (wlog == WelsLogDefault) {
str_t fname[MAX_FNAME_LEN] = {0};
-#if defined (_MSC_VER)
-#if _MSC_VER>=1500
- SNPRINTF (fname, MAX_FNAME_LEN, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
- pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
-#else
- SNPRINTF (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
- pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
-#endif//_MSC_VER>=1500
-#else
- //GNUC/
- SNPRINTF (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
- pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
-#endif//_MSC_VER
+ WelsSnprintf (fname, MAX_FNAME_LEN, "%swels_svc_encoder_trace.txt",
+ pCodingParam->sTracePath); // confirmed_safe_unsafe_usage
pCtx->pFileLog = WelsFopen (fname, "wt+");
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -456,12 +456,12 @@
WelsEventInit (&pSmt->pFinUpdateMbListEvent[iIdx]);
#else
// length of semaphore name should be system constrained at least on mac 10.7
- SNPRINTF (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (name, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pUpdateMbListEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
#endif
- SNPRINTF (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (name, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pFinUpdateMbListEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pFinUpdateMbListEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
@@ -475,12 +475,12 @@
WelsEventInit (&pSmt->pFinSliceCodingEvent[iIdx]);
WelsEventInit (&pSmt->pExitEncodeEvent[iIdx]);
#else
- SNPRINTF (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (name, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pSliceCodedEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pSliceCodedEvent%d named(%s) ret%d err%d\n", iIdx, name, err, errno);
#endif
- SNPRINTF (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (name, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
err = WelsEventOpen (&pSmt->pReadySliceCodingEvent[iIdx], name);
#if defined(ENABLE_TRACE_MT)
WelsLog ((*ppCtx), WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d\n", iIdx,
@@ -574,14 +574,14 @@
#else
str_t ename[SEM_NAME_MAX] = {0};
// length of semaphore name should be system constrained at least on mac 10.7
- SNPRINTF (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (ename, SEM_NAME_MAX, "sc%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pSliceCodedEvent[iIdx], ename);
- SNPRINTF (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (ename, SEM_NAME_MAX, "rc%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pReadySliceCodingEvent[iIdx], ename);
#if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE)
- SNPRINTF (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (ename, SEM_NAME_MAX, "ud%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pUpdateMbListEvent[iIdx], ename);
- SNPRINTF (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
+ WelsSnprintf (ename, SEM_NAME_MAX, "fu%d%p", iIdx, (void*) (*ppCtx));
WelsEventClose (pSmt->pFinUpdateMbListEvent[iIdx], ename);
#endif//DYNAMIC_SLICE_ASSIGN && TRY_SLICING_BALANCE
#endif//_WIN32
@@ -1224,7 +1224,7 @@
dw = SetThreadAffinityMask (pCtx->pSliceThreading->pThreadHandles[iIdx], dwAffinityMask); //1 << iIdx
if (dw == 0) {
str_t str[64] = {0};
- SNPRINTF (str, 64, "SetThreadAffinityMask iIdx:%d", iIdx);
+ WelsSnprintf (str, 64, "SetThreadAffinityMask iIdx:%d", iIdx);
}
}
}
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -170,13 +170,7 @@
t_now = (struct tm*)LOCALTIME (&l_time);
gettimeofday (&tv, NULL);
#endif//WIN32
-#ifdef _MSC_VER
-#if _MSC_VER >= 1500
- iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
-#else
- iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
-#endif//_MSC_VER >= 1500
-#endif//_MSC_VER
+ iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx); // confirmed_safe_unsafe_usage
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;
iBufLeft -= iCurUsed;
@@ -230,16 +224,10 @@
if (iBufLeft > 0) {
#if defined (_WIN32)
-#ifdef _MSC_VER
-#if _MSC_VER >= 1500
- iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, ".%03.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
-#else
- iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
-#endif//_MSC_VER >= 1500
-#endif//_MSC_VER
+ iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tb.millitm); // confirmed_safe_unsafe_usage
#elif defined (__GNUC__)
- iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ",
- static_cast<unsigned int> (tv.tv_usec / 1000)); // confirmed_safe_unsafe_usage
+ iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ",
+ static_cast<unsigned int> (tv.tv_usec / 1000)); // confirmed_safe_unsafe_usage
#endif//WIN32
if (iCurUsed >= 0) {
iBufUsed += iCurUsed;
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -117,20 +117,8 @@
gettimeofday (&tTimev, NULL);
#endif//WIN32
-#ifdef _WIN32
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
- iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, iBufferLeft, "enc_bs_0x%p_", (void*)this);
- iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
-#else
- iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
- iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#else
- iCurUsed = SNPRINTF (strStreamFileName, iBufferLeft, "/tmp/enc_bs_0x%p_", (void*)this);
- iCurUsedSize = SNPRINTF (strLenFileName, iBufferLeftSize, "/tmp/enc_size_0x%p", (void*)this);
-#endif//WIN32
+ iCurUsed = WelsSnprintf (strStreamFileName, iBufferLeft, "enc_bs_0x%p_", (void*)this);
+ iCurUsedSize = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
if (iCurUsed > 0) {
@@ -179,15 +167,9 @@
if (iBufferLeft > 0) {
#ifdef _WIN32
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
- iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, iBufferLeft, ".%03.3u.264", tTimeb.millitm);
+ iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
#else
- iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimeb.millitm);
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#else
- iCurUsed = SNPRINTF (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
+ iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264", tTimev.tv_usec / 1000);
#endif//WIN32
if (iCurUsed > 0) {
iBufferUsed += iCurUsed;
@@ -197,16 +179,9 @@
if (iBufferLeftSize > 0) {
#ifdef _WIN32
-#if defined(_MSC_VER)
-#if _MSC_VER>=1500
- iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, iBufferLeftSize, ".%03.3u.len",
- tTimeb.millitm);
+ iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
#else
- iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimeb.millitm);
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-#else
- iCurUsedSize = SNPRINTF (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
+ iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len", tTimev.tv_usec / 1000);
#endif//WIN32
if (iCurUsedSize > 0) {
iBufferUsedSize += iCurUsedSize;
@@ -492,17 +467,11 @@
#if defined(OUTPUT_BIT_STREAM) || defined(ENABLE_TRACE_FILE)
str_t fpath[MAX_FNAME_LEN] = {0};
#if defined(__GNUC__)
- SNPRINTF (fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage
+ WelsSnprintf (fpath, MAX_FNAME_LEN, "/tmp/"); // confirmed_safe_unsafe_usage
#else//__GNUC__
-#if defined (_MSC_VER)
-#if _MSC_VER>=1500
- SNPRINTF (fpath, MAX_FNAME_LEN, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
-#else
- SNPRINTF (fpath, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
+ WelsSnprintf (fpath, MAX_FNAME_LEN, ".\\"); // confirmed_safe_unsafe_usage
#endif //__GNUC__
strcpy (pCfg->sTracePath, fpath); // confirmed_safe_unsafe_usage
@@ -681,36 +650,13 @@
m_pFileBsSize = NULL;
}
str_t strStreamFileName[128] = {0};
-#if defined(__GNUC__)
-
- int32_t iLen = SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d.264", m_pEncContext->sTracePath, m_iSwitchTimes,
- m_pEncContext->pSvcParam->iActualPicWidth);
+ int32_t iLen = WelsSnprintf (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
+ m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBs = WelsFopen (strStreamFileName, "wb");
- SNPRINTF (strStreamFileName, 128, "%sadj%d_w%d_size.iLen", m_pEncContext->sTracePath, m_iSwitchTimes,
- m_pEncContext->pSvcParam->iActualPicWidth);
+ WelsSnprintf (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
+ m_pEncContext->pSvcParam->iActualPicWidth);
m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
-#else//__GNUC__
-
-#if defined (_MSC_VER)
-#if _MSC_VER>=1500
- int32_t iLen = SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d.264", m_iSwitchTimes,
- m_pEncContext->pSvcParam->iActualPicWidth);
- m_pFileBs = WelsFopen (strStreamFileName, "wb");
- SNPRINTF (strStreamFileName, 128, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes,
- m_pEncContext->pSvcParam->iActualPicWidth);
- m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
-#else
- int32_t iLen = SNPRINTF (strStreamFileName, 128, "adj%d_w%d.264", m_iSwitchTimes,
- m_pEncContext->pSvcParam->iActualPicWidth);
- m_pFileBs = WelsFopen (strStreamFileName, "wb");
- SNPRINTF (strStreamFileName, 128, "adj%d_w%d_size.iLen", m_iSwitchTimes, m_pEncContext->pSvcParam->iActualPicWidth);
- m_pFileBsSize = WelsFopen (strStreamFileName, "wb");
-#endif//_MSC_VER>=1500
-#endif//_MSC_VER
-
-
-#endif//__GNUC__
m_bSwitch = FALSE;
}