From: Bastian Dehn Date: Sun, 16 Nov 2025 15:32:38 +0000 (+0100) Subject: change simplify validate string X-Git-Tag: 1.3.9^2~10 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=0e5ef622d97ea10744a9dc7cde1c001594a8623b;p=feierabend.git change simplify validate string --- diff --git a/src/validate.c b/src/validate.c index 0b1c7f8..5120791 100644 --- a/src/validate.c +++ b/src/validate.c @@ -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(®ex, regex_pattern, REG_NOSUB | REG_EXTENDED); + if (comp_success != 0) return false; - if (match == 0) - return true; + int match = regexec(®ex, str, 0, NULL, 0); - return false; + regfree(®ex); + return match == REG_NOERROR; } bool validate_datestring(const char* date)