瀏覽代碼

Merge pull request #1239 from bpay/asan-fixes

Fix errors flagged by address sanitizer
Areloch 10 年之前
父節點
當前提交
6e681dd82f
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 4 2
      Engine/source/gui/controls/guiTextCtrl.cpp
  2. 4 2
      Engine/source/platformWin32/winFileio.cpp

+ 4 - 2
Engine/source/gui/controls/guiTextCtrl.cpp

@@ -187,8 +187,10 @@ void GuiTextCtrl::setText(const char *txt)
    //make sure we don't call this before onAdd();
    if( !mProfile )
       return;
-   
-   if (txt)
+
+   // The txt pointer is sometimes the same as the mText pointer, so make sure
+   // we don't call strncpy with overlapping src and dest.
+   if (txt && txt != mText)
       dStrncpy(mText, (UTF8*)txt, MAX_STRING_LENGTH);
    mText[MAX_STRING_LENGTH] = '\0';
    

+ 4 - 2
Engine/source/platformWin32/winFileio.cpp

@@ -1306,8 +1306,10 @@ static bool recurseDumpDirectories(const char *basePath, const char *subPath, Ve
    // Compose our search string - Format : ([path]/[subpath]/*)
    //-----------------------------------------------------------------------------
 
-   char trail = basePath[ dStrlen(basePath) - 1 ];
-   char subTrail = subPath ? subPath[ dStrlen(subPath) - 1 ] : '\0';
+   dsize_t trLen = basePath ? dStrlen(basePath) : 0;
+   dsize_t subtrLen = subPath ? dStrlen(subPath) : 0;
+   char trail = trLen > 0 ? basePath[ trLen - 1 ] : '\0';
+   char subTrail = subtrLen > 0 ? subPath[ subtrLen - 1 ] : '\0';
 
    if( trail == '/' )
    {