shithub: openh264

Download patch

ref: 3c40261256f6e89bd868f9fafba8b9c4fd9ea15d
parent: 0d7bafcebcfde8e1536791e9d387fa11fe6f43d4
parent: e0da5a1686026e6c41695d1e13918acba8fe5cc7
author: Ethan Hugg <[email protected]>
date: Tue Jan 28 04:42:56 EST 2014

Merge pull request #251 from mstorsjo/crt-string-cleanup

Clean up the rest of the usage of crt_safe_util_x

--- a/codec/common/crt_util_safe_x.cpp
+++ b/codec/common/crt_util_safe_x.cpp
@@ -48,9 +48,6 @@
 #include <sys/timeb.h>
 #ifndef _MSC_VER
 #include <sys/time.h>
-#ifndef HAVE_STRNLEN
-#define strnlen(a,b) strlen(a)
-#endif //!HAVE_STRNLEN
 #endif //!_MSC_VER
 #else
 #include <sys/time.h>
@@ -77,16 +74,12 @@
   return iRc;
 }
 
-str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  strncpy_s (pDest, iSizeInBytes, kpSrc, iCount);
+str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc) {
+  strncpy_s (pDest, iSizeInBytes, kpSrc, _TRUNCATE);
 
   return pDest;
 }
 
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strnlen_s (kpStr, iMaxlen);
-}
-
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
   return vsnprintf_s (pBuffer, iSizeOfBuffer, _TRUNCATE, kpFormat, pArgPtr);
 }
@@ -137,16 +130,13 @@
   return iRc;
 }
 
-str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
+str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc) {
+  strncpy (pDest, kpSrc, iSizeInBytes); //confirmed_safe_unsafe_usage
+  pDest[iSizeInBytes - 1] = '\0';
 
   return pDest;
 }
 
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strlen (kpStr); //confirmed_safe_unsafe_usage
-}
-
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
   int32_t iRc = vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
   if (iRc < 0)
@@ -198,30 +188,12 @@
   return iRc;
 }
 
-str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  return strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
+str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc) {
+  strncpy (pDest, kpSrc, iSizeInBytes); //confirmed_safe_unsafe_usage
+  pDest[iSizeInBytes - 1] = '\0';
+  return pDest;
 }
 
-#if !defined(MACOS) && !defined(UNIX) && !defined(APPLE_IOS)
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strnlen (kpStr, iMaxlen); //confirmed_safe_unsafe_usage
-}
-#else
-int32_t WelsStrnlen (const str_t* kpString, int32_t iMaxlen) {
-  // In mac os, there is no strnlen in string.h, we can only use strlen instead of strnlen or
-  // implement strnlen by ourself
-
-#if 1
-  return strlen (kpString); //confirmed_safe_unsafe_usage
-#else
-  const str_t* kpSrc;
-  for (kpSrc = kpString; iMaxlen-- && *kpSrc != '\0'; ++kpSrc)
-    return kpSrc - kpString;
-#endif
-
-}
-#endif
-
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
   return vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
 }
@@ -261,6 +233,11 @@
 
 #endif
 
+
+str_t* WelsStrcat (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc) {
+    int32_t iCurLen = strlen(pDest);
+    return WelsStrncpy(pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
+}
 
 int32_t WelsFwrite (const void_t* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {
   return fwrite (kpBuffer, iSize, iCount, pFp);
--- a/codec/common/crt_util_safe_x.h
+++ b/codec/common/crt_util_safe_x.h
@@ -76,9 +76,8 @@
 #endif
 
 int32_t   WelsSnprintf (str_t* buffer,  int32_t sizeOfBuffer,  const str_t* format, ...);
-str_t*   WelsStrncpy (str_t* dest, int32_t sizeInBytes, const str_t* src, int32_t count);
-str_t*   WelsStrcat (str_t* dest, int32_t sizeInBytes, str_t* src);
-int32_t   WelsStrnlen (const str_t* str,  int32_t maxlen);
+str_t*   WelsStrncpy (str_t* dest, int32_t sizeInBytes, const str_t* src);
+str_t*   WelsStrcat (str_t* dest, int32_t sizeInBytes, const str_t* src);
 int32_t   WelsVsnprintf (str_t* buffer, int32_t sizeOfBuffer, const str_t* format, va_list argptr);
 
 WelsFileHandle*        WelsFopen (const str_t* filename,  const str_t* mode);
@@ -96,345 +95,5 @@
 #ifdef __cplusplus
 }
 #endif
-
-
-/*
- * Safe Lib specific errno codes.  These can be added to the errno.h file
- * if desired.
- */
-#define ESNULLP         ( 400 )       /* null ptr                    */
-#define ESZEROL         ( 401 )       /* length is zero              */
-#define ESLEMIN         ( 402 )       /* length is below min         */
-#define ESLEMAX         ( 403 )       /* length exceeds max          */
-#define ESOVRLP         ( 404 )       /* overlap undefined           */
-#define ESEMPTY         ( 405 )       /* empty string                */
-#define ESNOSPC         ( 406 )       /* not enough space for s2     */
-#define ESUNTERM        ( 407 )       /* unterminated string         */
-#define ESNODIFF        ( 408 )       /* no difference               */
-#define ESNOTFND        ( 409 )       /* not found                   */
-
-/* EOK may or may not be defined in errno.h */
-#ifndef EOK
-#define EOK   0
-#endif
-
-#if (defined(WIN32) && defined(_MSC_VER) && (_MSC_VER<1500)) || defined(__GNUC__)
-
-static inline int wels_strncpy_s (char* dest, int dmax, const char* src, int slen) {
-int orig_dmax;
-char* orig_dest;
-const char* overlap_bumper;
-
-if (dest == NULL) {
-//        invoke_safe_lib_constraint_handler("strncpy_s: dest is null",
-//                   NULL, ESNULLP);
-  return (ESNULLP);
-}
-
-if (dmax <= 0) {
-//        invoke_safe_lib_constraint_handler("strncpy_s: dmax is 0",
-//                   NULL, ESZEROL);
-  return (ESZEROL);
-}
-
-//    if (dmax > RSIZE_MAX_STR) {
-//        invoke_safe_lib_constraint_handler("strncpy_s: dmax exceeds max",
-//                   NULL, ESLEMAX);
-//        return (ESLEMAX);
-//    }
-
-if (src == NULL) {
-//        handle_error(orig_dest, orig_dmax, "strncpy_s: src is null", ESNULLP);
-  return (ESNULLP);
-}
-
-if (slen <= 0) {
-//        handle_error(orig_dest, orig_dmax, "strncpy_s: slen is zero", ESZEROL);
-  return (ESZEROL);
-}
-
-//    if (slen > RSIZE_MAX_STR) {
-//        handle_error(orig_dest, orig_dmax, "strncpy_s: slen exceeds max", ESLEMAX);
-//        return (ESLEMAX);
-//    }
-
-/* hold base in case src was not copied */
-orig_dmax = dmax;
-orig_dest = dest;
-
-if (dest < src) {
-  overlap_bumper = src;
-
-  while (dmax > 0) {
-    if (dest == overlap_bumper) {
-//                handle_error(orig_dest, orig_dmax, "strncpy_s: overlapping objects", ESOVRLP);
-      return (ESOVRLP);
-    }
-
-    if (slen == 0) {
-      /*
-       * Copying truncated to slen chars.  Note that the TR says to
-       * copy slen chars plus the null char.  We null the slack.
-       */
-#ifdef SAFE_LIB_STR_NULL_SLACK
-      while (dmax) {
-        *dest = '\0';
-        dmax--;
-        dest++;
-      }
-#else
-      *dest = '\0';
-#endif
-      return (EOK);
-    }
-
-    *dest = *src;
-    if (*dest == '\0') {
-#ifdef SAFE_LIB_STR_NULL_SLACK
-      /* null slack */
-      while (dmax) {
-        *dest = '\0';
-        dmax--;
-        dest++;
-      }
-#endif
-      return (EOK);
-    }
-
-    dmax--;
-    slen--;
-    dest++;
-    src++;
-  }
-
-} else {
-  overlap_bumper = dest;
-
-  while (dmax > 0) {
-    if (src == overlap_bumper) {
-//                handle_error(orig_dest, orig_dmax, "strncpy_s: overlapping objects", ESOVRLP);
-      return (ESOVRLP);
-    }
-
-    if (slen == 0) {
-      /*
-       * Copying truncated to slen chars.  Note that the TR says to
-       * copy slen chars plus the null char.  We null the slack.
-       */
-#ifdef SAFE_LIB_STR_NULL_SLACK
-      while (dmax) {
-        *dest = '\0';
-        dmax--;
-        dest++;
-      }
-#else
-      *dest = '\0';
-#endif
-      return (EOK);
-    }
-
-    *dest = *src;
-    if (*dest == '\0') {
-#ifdef SAFE_LIB_STR_NULL_SLACK
-      /* null slack */
-      while (dmax) {
-        *dest = '\0';
-        dmax--;
-        dest++;
-      }
-#endif
-      return (EOK);
-    }
-
-    dmax--;
-    slen--;
-    dest++;
-    src++;
-  }
-}
-
-/*
- * the entire src was not copied, so zero the string
- */
-//    handle_error(orig_dest, orig_dmax, "strncpy_s: not enough space for src", ESNOSPC);
-return (ESNOSPC);
-}
-
-static inline int wels_strcat_s (char* dest, int dmax, const char* src) {
-  int orig_dmax;
-  char* orig_dest;
-  const char* overlap_bumper;
-
-  if (dest == NULL) {
-//        invoke_safe_lib_constraint_handler("strcat_s: dest is null",
-//                   NULL, ESNULLP);
-    return (ESNULLP);
-  }
-
-  if (src == NULL) {
-//        invoke_safe_lib_constraint_handler("strcat_s: src is null",
-//                   NULL, ESNULLP);
-    return (ESNULLP);
-  }
-
-  if (dmax <= 0) {
-//        invoke_safe_lib_constraint_handler("strcat_s: dmax is 0",
-//                   NULL, ESZEROL);
-    return (ESZEROL);
-  }
-
-//    if (dmax > RSIZE_MAX_STR) {
-//        invoke_safe_lib_constraint_handler("strcat_s: dmax exceeds max",
-//                   NULL, ESLEMAX);
-//        return (ESLEMAX);
-//    }
-
-  /* hold base of dest in case src was not copied */
-  orig_dmax = dmax;
-  orig_dest = dest;
-
-  if (dest < src) {
-    overlap_bumper = src;
-
-    /* Find the end of dest */
-    while (*dest != '\0') {
-
-      if (dest == overlap_bumper) {
-//                handle_error(orig_dest, orig_dmax, "strcat_s: overlapping objects", ESOVRLP);
-        return (ESOVRLP);
-      }
-
-      dest++;
-      dmax--;
-      if (dmax == 0) {
-//                handle_error(orig_dest, orig_dmax, "strcat_s: dest unterminated", ESUNTERM);
-        return (ESUNTERM);
-      }
-    }
-
-    while (dmax > 0) {
-      if (dest == overlap_bumper) {
-//                handle_error(orig_dest, orig_dmax, "strcat_s: overlapping objects", ESOVRLP);
-        return (ESOVRLP);
-      }
-
-      *dest = *src;
-      if (*dest == '\0') {
-#ifdef SAFE_LIB_STR_NULL_SLACK
-        /* null slack to clear any data */
-        while (dmax) {
-          *dest = '\0';
-          dmax--;
-          dest++;
-        }
-#endif
-        return (EOK);
-      }
-
-      dmax--;
-      dest++;
-      src++;
-    }
-
-  } else {
-    overlap_bumper = dest;
-
-    /* Find the end of dest */
-    while (*dest != '\0') {
-
-      /*
-       * NOTE: no need to check for overlap here since src comes first
-       * in memory and we're not incrementing src here.
-       */
-      dest++;
-      dmax--;
-      if (dmax == 0) {
-//                handle_error(orig_dest, orig_dmax, "strcat_s: dest unterminated", ESUNTERM);
-        return (ESUNTERM);
-      }
-    }
-
-    while (dmax > 0) {
-      if (src == overlap_bumper) {
-//                handle_error(orig_dest, orig_dmax, "strcat_s: overlapping objects", ESOVRLP);
-        return (ESOVRLP);
-      }
-
-      *dest = *src;
-      if (*dest == '\0') {
-#ifdef SAFE_LIB_STR_NULL_SLACK
-        /* null slack to clear any data */
-        while (dmax) {
-          *dest = '\0';
-          dmax--;
-          dest++;
-        }
-#endif
-        return (EOK);
-      }
-
-      dmax--;
-      dest++;
-      src++;
-    }
-  }
-
-  /*
-   * the entire src was not copied, so null the string
-   */
-//    handle_error(orig_dest, orig_dmax, "strcat_s: not enough space for src", ESNOSPC);
-
-  return (ESNOSPC);
-}
-
-static inline int wels_strnlen_s (const char* dest, int dmax) {
-  int count;
-
-  if (dest == NULL) {
-    return (0);
-  }
-
-  if (dmax <= 0) {
-//        invoke_safe_lib_constraint_handler("strnlen_s: dmax is 0",
-//                   NULL, ESZEROL);
-    return (0);
-  }
-
-//    if (dmax > RSIZE_MAX_STR) {
-//        invoke_safe_lib_constraint_handler("strnlen_s: dmax exceeds max",
-//                   NULL, ESLEMAX);
-//        return (0);
-//    }
-
-  count = 0;
-  while (*dest && dmax) {
-    count++;
-    dmax--;
-    dest++;
-  }
-
-  return (count);
-}
-
-#endif//(WIN32 && _MSC_VER && _MSC_VER<1500) || __GNUC__
-
-#if defined(WIN32) && defined(_MSC_VER)
-#if _MSC_VER >= 1500	// VS2008
-#define STRNCPY		strncpy_s
-#define STRCAT		strcat_s
-#define STRNLEN		strnlen_s
-#else	// mainly for VC6
-#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
-#define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
-#endif//_MSC_VER >= 1500
-
-#else//__GNUC__
-
-#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
-#define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
-
-#endif//WIN32
 
 #endif//WELS_CRT_UTIL_SAFE_CROSS_PLATFORMS_H__
--- a/codec/decoder/plus/src/welsCodecTrace.cpp
+++ b/codec/decoder/plus/src/welsCodecTrace.cpp
@@ -60,9 +60,9 @@
 int32_t  CWelsTraceBase::Trace (const int kLevel, const str_t* kpFormat, va_list pVl) {
   if (kLevel & m_iLevel) {
     str_t chBuf[MAX_LOG_SIZE] = {0};
-    const int32_t kLen	= WelsStrnlen ((const str_t*)"[DECODER]: ", MAX_LOG_SIZE);
+    const int32_t kLen	= strlen ("[DECODER]: ");
 
-    WelsStrncpy (chBuf, MAX_LOG_SIZE, (const str_t*)"[DECODER]: ", kLen);
+    WelsStrncpy (chBuf, MAX_LOG_SIZE, (const str_t*)"[DECODER]: ");
 
     WelsVsnprintf ((chBuf + kLen),  MAX_LOG_SIZE - kLen, (const str_t*)kpFormat, pVl);
 
@@ -87,8 +87,8 @@
   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 (chEnter, 1, WelsStrnlen (chEnter,  16), m_pTraceFile);
+    iRC += WelsFwrite (pStr, 1, strlen (pStr), m_pTraceFile);
+    iRC += WelsFwrite (chEnter, 1, strlen (chEnter), m_pTraceFile);
     WelsFflush (m_pTraceFile);
   }
   return iRC;
@@ -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/property.cpp
+++ b/codec/encoder/core/src/property.cpp
@@ -64,12 +64,11 @@
   if (NULL == pBuf)
     return 0;
 
-  iLen = STRNLEN (WELS_CODE_NAME, 4);	// confirmed_safe_unsafe_usage
+  iLen = strlen (WELS_CODE_NAME);	// confirmed_safe_unsafe_usage
   if (iSize <= iLen)
     return 0;
 
-  pBuf[iLen]	= '\0';
-  STRNCPY (pBuf, iSize, WELS_CODE_NAME, iLen);	// confirmed_safe_unsafe_usage
+  WelsStrncpy (pBuf, iSize, WELS_CODE_NAME);	// confirmed_safe_unsafe_usage
 
   return iLen;
 }
@@ -86,12 +85,11 @@
   if (NULL == pBuf)
     return 0;
 
-  iLen	= STRNLEN (WELS_LIB_NAME, 7);	// confirmed_safe_unsafe_usage
+  iLen	= strlen (WELS_LIB_NAME);	// confirmed_safe_unsafe_usage
   if (iSize <= iLen)
     return 0;
 
-  pBuf[iLen]	= '\0';
-  STRNCPY (pBuf, iSize, WELS_LIB_NAME, iLen);	// confirmed_safe_unsafe_usage
+  WelsStrncpy (pBuf, iSize, WELS_LIB_NAME);	// confirmed_safe_unsafe_usage
 
   return iLen;
 }
@@ -108,12 +106,11 @@
   if (NULL == pBuf)
     return 0;
 
-  iLen	= STRNLEN (WELS_VERSION_STR, 5);	// confirmed_safe_unsafe_usage
+  iLen	= strlen (WELS_VERSION_STR);	// confirmed_safe_unsafe_usage
   if (iSize <= iLen)
     return 0;
 
-  pBuf[iLen]	= '\0';
-  STRNCPY (pBuf, iSize, WELS_VERSION_STR, iLen);	// confirmed_safe_unsafe_usage
+  WelsStrncpy (pBuf, iSize, WELS_VERSION_STR);	// confirmed_safe_unsafe_usage
 
   return iLen;
 }
@@ -130,12 +127,11 @@
   if (NULL == pBuf)
     return 0;
 
-  iLen	= STRNLEN (WELS_IDENT, 30);	// confirmed_safe_unsafe_usage
+  iLen	= strlen (WELS_IDENT);	// confirmed_safe_unsafe_usage
   if (iSize <= iLen)
     return 0;
 
-  pBuf[iLen]	= '\0';
-  STRNCPY (pBuf, iSize, WELS_IDENT, iLen);	// confirmed_safe_unsafe_usage
+  WelsStrncpy (pBuf, iSize, WELS_IDENT);	// confirmed_safe_unsafe_usage
 
   return iLen;
 }
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -207,14 +207,12 @@
       int32_t i_shift = 0;
       str_t* pStr = NULL;
       pStr	= GetLogTag (kiLevel, &i_shift);
-      if (NULL != pCtx) {
-        int32_t iLenTag = STRNLEN (pStr, 8);	// confirmed_safe_unsafe_usage
-        STRCAT (&pBuf[iBufUsed], iBufLeft, pStr);	// confirmed_safe_unsafe_usage
-        iBufUsed += iLenTag;
-        pBuf[iBufUsed] = ' ';
-        iBufUsed++;
-        ++iLenTag;
-        iBufLeft -= iLenTag;
+      if (NULL != pStr) {
+        iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "%s ", pStr);
+        if (iCurUsed >= 0) {
+          iBufUsed += iCurUsed;
+          iBufLeft -= iCurUsed;
+        }
       }
     }
     if (iBufLeft > 0) {
@@ -264,15 +262,11 @@
 #ifdef ENABLE_TRACE_FILE
   sWelsEncCtx* pEncCtx	= (sWelsEncCtx*)pCtx;
   if (wlog == WelsLogDefault) {
-    int32_t len = 0;
     if (pEncCtx->pFileLog != NULL) {
       WelsFclose (pEncCtx->pFileLog);
       pEncCtx->pFileLog = NULL;
     }
     pEncCtx->uiSizeLog	= 0;
-    len = STRNLEN (pCurPath, MAX_FNAME_LEN - 1);	// confirmed_safe_unsafe_usage
-    if (len >= MAX_FNAME_LEN)
-      return;
     pEncCtx->pFileLog	= WelsFopen ("wels_encoder_trace.txt", "wt+");	// confirmed_safe_unsafe_usage
   }
 #endif//ENABLE_TRACE_FILE
--- a/codec/encoder/plus/src/welsCodecTrace.cpp
+++ b/codec/encoder/plus/src/welsCodecTrace.cpp
@@ -120,10 +120,10 @@
   }
 
   str_t pBuf[MAX_LOG_SIZE] = {0};
-  const int32_t len	= STRNLEN ("[ENCODER]: ", MAX_LOG_SIZE);	// confirmed_safe_unsafe_usage
+  const int32_t len	= strlen ("[ENCODER]: ");	// confirmed_safe_unsafe_usage
 
 
-  STRNCPY (pBuf, MAX_LOG_SIZE, "[ENCODER]: ", len);	// confirmed_safe_unsafe_usage
+  WelsStrncpy (pBuf, MAX_LOG_SIZE, "[ENCODER]: ");	// confirmed_safe_unsafe_usage
   WelsVsnprintf (pBuf + len, MAX_LOG_SIZE - len, Str_Format, vl);	// confirmed_safe_unsafe_usage
 
 //		g_WelsCodecTrace.TraceString(iLevel, pBuf);
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -994,20 +994,20 @@
   str_t strFileName[256] = {0};
   const int32_t iDataLength = m_iMaxPicWidth * m_iMaxPicHeight;
 
-  STRNCPY (strFileName, 256, "pic_in_", STRNLEN ("pic_in_", 255));	// confirmed_safe_unsafe_usage
+  WelsStrncpy (strFileName, 256, "pic_in_");	// confirmed_safe_unsafe_usage
 
   if (m_iMaxPicWidth == 640) {
-    STRCAT (strFileName, 256, "360p.");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "360p.");	// confirmed_safe_unsafe_usage
   } else if (m_iMaxPicWidth == 320) {
-    STRCAT (strFileName, 256, "180p.");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "180p.");	// confirmed_safe_unsafe_usage
   } else if (m_iMaxPicWidth == 160) {
-    STRCAT (strFileName, 256, "90p.");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "90p.");	// confirmed_safe_unsafe_usage
   }
 
   switch (m_iCspInternal) {
   case videoFormatI420:
   case videoFormatYV12:
-    STRCAT (strFileName, 256, "yuv");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "yuv");	// confirmed_safe_unsafe_usage
     pFile = WelsFopen (strFileName, "ab+");
     //				WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_I420, m_iCspInternal= 0x%x\n", m_iCspInternal);
     if (NULL != pFile) {
@@ -1017,7 +1017,7 @@
     }
     break;
   case videoFormatRGB:
-    STRCAT (strFileName, 256, "rgb");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "rgb");	// confirmed_safe_unsafe_usage
     pFile = WelsFopen (strFileName, "ab+");
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), iDataLength * 3, pFile);
@@ -1025,7 +1025,7 @@
       fclose (pFile);
     }
   case videoFormatBGR:
-    STRCAT (strFileName, 256, "bgr");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "bgr");	// confirmed_safe_unsafe_usage
     pFile = WelsFopen (strFileName, "ab+");
     //				WelsLog( m_pEncContext, WELS_LOG_INFO, "WELS_CSP_BGR, m_iCspInternal= 0x%x\n", m_iCspInternal);
     if (NULL != pFile) {
@@ -1035,7 +1035,7 @@
     }
     break;
   case videoFormatYUY2:
-    STRCAT (strFileName, 256, "yuy2");	// confirmed_safe_unsafe_usage
+    WelsStrcat (strFileName, 256, "yuy2");	// confirmed_safe_unsafe_usage
     pFile = WelsFopen (strFileName, "ab+");
     if (NULL != pFile) {
       fwrite (pSrc, sizeof (uint8_t), (CALC_BI_STRIDE (m_iMaxPicWidth,  16)) * m_iMaxPicHeight, pFile);