ref: 92fa4eb4000a9f3c33e14d917f133806d857a4a4
parent: 082a986990bbb529eb5cea2e1576332ac00d9b56
author: Martin Storsjö <martin@martin.st>
date: Tue Jan 28 06:12:53 EST 2014
Use strlen instead of WelsStrnlen/STRNLEN for known null terminated strings strlen is not dangerous if the string is known to be null terminated (and MSVC does not warn about its use either). For the cases in the decoder welsCodecTrace.cpp, the string passed to all WriteString instances is produced by WelsVsnprintf which always null terminates the buffer nowadays. Additionally, as the string was passed to OutputDebugStringA without any length specifier before, it was already assumed to be null terminated. The file name parameter passed to DumpDependencyRec and DumpRecFrame in encoder.cpp is always null terminated, which was already assumed as it is passed to WelsFopen as is. As for the encoder utils.cpp, the strings returned by GetLogPath are string constants that are null terminated.
--- a/codec/decoder/plus/src/welsCodecTrace.cpp
+++ b/codec/decoder/plus/src/welsCodecTrace.cpp
@@ -87,7 +87,7 @@
int iRC = 0;
const static str_t chEnter[16] = "\n";
if (m_pTraceFile) {
- iRC += WelsFwrite (pStr, 1, WelsStrnlen (pStr, MAX_LOG_SIZE), m_pTraceFile);
+ iRC += WelsFwrite (pStr, 1, strlen (pStr), m_pTraceFile);
iRC += WelsFwrite (chEnter, 1, strlen (chEnter), m_pTraceFile);
WelsFflush (m_pTraceFile);
}
@@ -100,7 +100,7 @@
int32_t CWelsTraceWinDgb::WriteString (int32_t iLevel, const str_t* pStr) {
OutputDebugStringA (pStr);
- return WelsStrnlen (pStr, MAX_LOG_SIZE); //strnlen(pStr, MAX_LOG_SIZE);
+ return strlen (pStr);
}
#endif
--- a/codec/encoder/core/src/encoder.cpp
+++ b/codec/encoder/core/src/encoder.cpp
@@ -323,7 +323,7 @@
return;
if (bDependencyRecFlag[kiDid]) {
- if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) // confirmed_safe_unsafe_usage
+ if (strlen (kpFileName) > 0) // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (kpFileName, "ab");
else {
str_t sDependencyRecFileName[16] = {0};
@@ -333,7 +333,7 @@
if (NULL != pDumpRecFile)
WelsFseek (pDumpRecFile, 0, SEEK_END);
} else {
- if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
+ if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (kpFileName, "wb");
} else {
str_t sDependencyRecFileName[16] = {0};
@@ -391,7 +391,7 @@
return;
if (bRecFlag) {
- if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
+ if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (kpFileName, "ab");
} else {
pDumpRecFile = WelsFopen ("rec.yuv", "ab");
@@ -399,7 +399,7 @@
if (NULL != pDumpRecFile)
WelsFseek (pDumpRecFile, 0, SEEK_END);
} else {
- if (STRNLEN (kpFileName, MAX_FNAME_LEN) > 0) { // confirmed_safe_unsafe_usage
+ if (strlen (kpFileName) > 0) { // confirmed_safe_unsafe_usage
pDumpRecFile = WelsFopen (kpFileName, "wb");
} else {
pDumpRecFile = WelsFopen ("rec.yuv", "wb");
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -208,7 +208,7 @@
str_t* pStr = NULL;
pStr = GetLogTag (kiLevel, &i_shift);
if (NULL != pCtx) {
- int32_t iLenTag = STRNLEN (pStr, 8); // confirmed_safe_unsafe_usage
+ int32_t iLenTag = strlen (pStr); // confirmed_safe_unsafe_usage
STRCAT (&pBuf[iBufUsed], iBufLeft, pStr); // confirmed_safe_unsafe_usage
iBufUsed += iLenTag;
pBuf[iBufUsed] = ' ';