From 26f53e7d475f01f38f4f4190285aafb31f828b60 Mon Sep 17 00:00:00 2001 From: tintin10q Date: Sat, 24 Jan 2026 07:38:28 +0000 Subject: [PATCH] Fix SACstrstr to return the index instead of the string Modify SACstrstr to return the index of the needle in the haystack or -1 if not found as was specified by the specification in String.sac. --- src/structures/src/String/Str.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/structures/src/String/Str.c b/src/structures/src/String/Str.c index 1ec9dd79..9762b5d2 100644 --- a/src/structures/src/String/Str.c +++ b/src/structures/src/String/Str.c @@ -360,7 +360,10 @@ sac_int SACstrspn(string str, string accept) sac_int SACstrstr(string haystack, string needle) { - return (sac_int)strstr(haystack, needle); + char * found = strstr(haystack, needle); + if (found == NULL) return -1; + sac_int index = found - haystack; + return index; } void SACstrtok(string* out_token, string* out_rest, string str, string delimiters)