AddressSanitizer: fix crash on completeLine 48/20748/3
Clément DAVID [Mon, 28 Jan 2019 13:35:58 +0000 (14:35 +0100)]
An invalid access has been introduced at 66eff04a, the
findMatchingPrefixSuffix function should always return a positive or
zero length.

Change-Id: Ic8ceadae82e809c679e7c6d8c5aed803b4fc6315

scilab/modules/completion/src/c/completeLine.c

index d969f87..ecb3895 100644 (file)
@@ -74,7 +74,15 @@ static int findMatchingPrefixSuffix(const char* string, const char* find, BOOL s
         {
             FREE(pointerOnFindCopy);
             pointerOnFindCopy = NULL;
-            return (int)(pointerOnString - string);
+
+            if (pointerOnString)
+            {
+                return (int)(pointerOnString - string);
+            }
+            else
+            {
+                return stringLength;
+            }
         }
         //Check if the cutted tmpfind match with the suffix of string that has adequat length
         pointerOnString = (char*)(string + stringLength - 1 - strlen(pointerOnFindCopy));