AddressSanitizer: fix some issues at first usage
[scilab.git] / scilab / modules / completion / src / c / completeLine.c
index ff38848..d969f87 100644 (file)
@@ -69,6 +69,13 @@ static int findMatchingPrefixSuffix(const char* string, const char* find, BOOL s
         }
         // Cut tmpfind at this position
         movingPointerOnFindCopy[0] = '\0';
+        // if a prefix is already found and could not grow anymore, return what we found
+        if (stringLength < strlen(pointerOnFindCopy))
+        {
+            FREE(pointerOnFindCopy);
+            pointerOnFindCopy = NULL;
+            return (int)(pointerOnString - string);
+        }
         //Check if the cutted tmpfind match with the suffix of string that has adequat length
         pointerOnString = (char*)(string + stringLength - 1 - strlen(pointerOnFindCopy));
         if ( !strnicmp(pointerOnFindCopy, pointerOnString, strlen(pointerOnFindCopy)) )