fileio: fix crash at Scilab startup 67/21367/2
Clément DAVID [Wed, 19 Feb 2020 16:11:04 +0000 (17:11 +0100)]
Change-Id: I1c724bc15a7d4e84545c46b8f7be792269ea462a

scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp

index 2c50dd4..3139401 100644 (file)
@@ -57,7 +57,8 @@ types::Function::ReturnValue sci_getlongpathname(types::typed_list &in, int _iRe
     {
         BOOL flagtrail = FALSE;
         wchar_t* tmp = getlongpathnameW(p[i], (BOOL*)&pBool[i]);
-        if (p[i][wcslen(p[i]) - 1] == '\\' || p[i][wcslen(p[i]) - 1] == '/')
+        size_t len = wcslen(p[i]);
+        if (len > 0 && (p[i][len - 1] == '\\' || p[i][len - 1] == '/'))
         {
             flagtrail = TRUE;
         }
index bb2badd..b734762 100644 (file)
@@ -60,7 +60,8 @@ types::Function::ReturnValue sci_getshortpathname(types::typed_list &in, int _iR
     {
         BOOL flagtrail = FALSE;
         wchar_t* tmp = getshortpathnameW(p[i], (BOOL*)&pBool[i]);
-        if (p[i][wcslen(p[i]) - 1] == '\\' || p[i][wcslen(p[i]) - 1] == '/')
+        size_t len = wcslen(p[i]);
+        if (len > 0 && (p[i][len - 1] == '\\' || p[i][len - 1] == '/'))
         {
             flagtrail = TRUE;
         }