Fix invalid read / write detected by valgrind 80/16480/2
Clément DAVID [Mon, 18 May 2015 18:34:20 +0000 (20:34 +0200)]
Change-Id: I6a073cf728882c74ee0e09606d64f2210a62d0b9

scilab/modules/ast/src/cpp/types/cell.cpp
scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp

index aac596e..509def9 100644 (file)
@@ -141,13 +141,14 @@ bool Cell::set(int _iRows, int _iCols, const InternalType* _pIT)
 
 bool Cell::set(int _iIndex, InternalType* _pIT)
 {
-    if (m_pRealData[_iIndex] == _pIT)
-    {
-        return true;
-    }
-
     if (_iIndex < getSize())
     {
+        // corner case when inserting twice
+        if (m_pRealData[_iIndex] == _pIT)
+        {
+            return true;
+        }
+
         if (m_pRealData[_iIndex] != NULL)
         {
             m_pRealData[_iIndex]->DecreaseRef();
index 8e11cf2..c30baef 100644 (file)
@@ -124,7 +124,7 @@ Function::ReturnValue sci_regexp(typed_list &in, int _iRetCount, typed_list &out
     piEnd       = new int[wcslen(pwstInput)];
 
     pwstCapturedString = (wchar_t***)MALLOC(sizeof(wchar_t**) * wcslen(pwstInput));
-    piCapturedStringCount = (int*)MALLOC(sizeof(int) * wcslen(pwstInput));
+    piCapturedStringCount = (int*)CALLOC(sizeof(int), wcslen(pwstInput));
 
     do
     {