]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change simplify validate string
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Nov 2025 15:32:38 +0000 (16:32 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Nov 2025 15:32:38 +0000 (16:32 +0100)
src/validate.c

index 0b1c7f8318f8b95b40bd1b43ae771bc3ec9b9513..5120791823c6962a390c88f103864d8a279406b2 100644 (file)
@@ -8,29 +8,16 @@
 
 bool validate_string(const char* str, const char* regex_pattern)
 {
-       regex_t* regex = malloc(sizeof(regex_t));
-       if (regex == NULL)
-               return false;
-
-       int comp_success = regcomp(regex, regex_pattern, REG_NOSUB | REG_EXTENDED);
-       if (comp_success != 0) {
-               free(regex);
-               return false;
-       }
-
-       int match = regexec(regex, str, 0, NULL, 0);
-
-       regfree(regex);
-       free(regex);
-       regex = NULL;
+       regex_t regex;
 
-       if (match == REG_NOMATCH)
+       int comp_success = regcomp(&regex, regex_pattern, REG_NOSUB | REG_EXTENDED);
+       if (comp_success != 0)
                return false;
 
-       if (match == 0)
-               return true;
+       int match = regexec(&regex, str, 0, NULL, 0);
 
-       return false;
+       regfree(&regex);
+       return match == REG_NOERROR;
 }
 
 bool validate_datestring(const char* date)