Init the string value and add protection for WelsStrcat()

This commit is contained in:
Haibo Zhu 2015-10-10 08:45:48 -07:00
parent 0b2d724c3e
commit a58e169ee8
3 changed files with 9 additions and 7 deletions

View File

@ -79,7 +79,7 @@ typedef struct TagWelsTime {
int32_t WelsSnprintf (char* buffer, int32_t sizeOfBuffer, const char* format, ...);
char* WelsStrncpy (char* dest, int32_t sizeInBytes, const char* src);
char* WelsStrcat (char* dest, int32_t sizeInBytes, const char* src);
char* WelsStrcat (char* dest, uint32_t sizeInBytes, const char* src);
int32_t WelsVsnprintf (char* buffer, int32_t sizeOfBuffer, const char* format, va_list argptr);
WelsFileHandle* WelsFopen (const char* filename, const char* mode);

View File

@ -75,8 +75,8 @@ int32_t WelsSnprintf (char* pBuffer, int32_t iSizeOfBuffer, const char* kpForma
return iRc;
}
char* WelsStrncpy (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
strncpy_s (pDest, iSizeInBytes, kpSrc, _TRUNCATE);
char* WelsStrncpy (char* pDest, uint32_t uiSizeInBytes, const char* kpSrc) {
strncpy_s (pDest, uiSizeInBytes, kpSrc, _TRUNCATE);
return pDest;
}
@ -242,9 +242,11 @@ int32_t WelsStrftime (char* pBuffer, int32_t iSize, const char* kpFormat, const
#endif
char* WelsStrcat (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
int32_t iCurLen = (int32_t)strlen (pDest);
return WelsStrncpy (pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
char* WelsStrcat (char* pDest, uint32_t uiSizeInBytes, const char* kpSrc) {
uint32_t uiCurLen = strlen (pDest);
if (uiSizeInBytes > uiCurLen)
return WelsStrncpy (pDest + uiCurLen, uiSizeInBytes - uiCurLen, kpSrc);
return pDest;
}
int32_t WelsFwrite (const void* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {

View File

@ -50,7 +50,7 @@ float WelsCalcPsnr (const void* kpTarPic,
void WelsLog (SLogContext* logCtx, int32_t iLevel, const char* kpFmt, ...) {
va_list vl;
char pTraceTag[MAX_LOG_SIZE];
char pTraceTag[MAX_LOG_SIZE] = {0};
switch (iLevel) {
case WELS_LOG_ERROR:
WelsSnprintf (pTraceTag, MAX_LOG_SIZE, "[OpenH264] this = 0x%p, Error:", logCtx->pCodecInstance);