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.
This commit is contained in:
Martin Storsjö 2014-01-28 11:12:53 +02:00
parent 082a986990
commit 92fa4eb400
3 changed files with 7 additions and 7 deletions

View File

@ -87,7 +87,7 @@ int32_t CWelsTraceFile::WriteString (int32_t iLevel, const str_t* pStr) {
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 CWelsTraceFile::WriteString (int32_t iLevel, const str_t* pStr) {
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

View File

@ -323,7 +323,7 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileNam
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 @@ extern "C" void DumpDependencyRec (SPicture* pCurPicture, const str_t* kpFileNam
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 @@ void DumpRecFrame (SPicture* pCurPicture, const str_t* kpFileName) {
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 @@ void DumpRecFrame (SPicture* pCurPicture, const str_t* kpFileName) {
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");

View File

@ -208,7 +208,7 @@ void WelsLogDefault (void* pCtx, const int32_t kiLevel, const str_t* kpFmtStr, v
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] = ' ';