Skip to content

Commit abdc145

Browse files
committed
Better fix than r19761
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19763 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent dcb3428 commit abdc145

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

SimulationRuntime/c/util/utility.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ extern int OpenModelica_regexImpl(const char* str, const char* re, const int max
5959
int nmatch=0,i,rc,res;
6060
int flags = (extended ? REG_EXTENDED : 0) | (sensitive ? REG_ICASE : 0) | (maxn ? 0 : REG_NOSUB);
6161
#if !defined(_MSC_VER)
62-
if (maxn < 1) {
63-
return 0;
64-
}
65-
regmatch_t matches[maxn];
62+
regmatch_t matches[maxn < 1 ? 1 : maxn];
6663
#else
6764
/* Stupid compiler */
6865
regmatch_t *matches;
69-
if (maxn < 1) {
70-
return 0;
71-
}
7266
matches = (regmatch_t*)malloc(maxn*sizeof(regmatch_t));
7367
assert(matches != NULL);
7468
#endif
7569
memset(&myregex, 1, sizeof(regex_t));
7670
rc = regcomp(&myregex, re, flags);
71+
if (rc && maxn == 0) {
72+
#if defined(_MSC_VER)
73+
free(matches);
74+
#endif
75+
return 0;
76+
}
7777
if (rc) {
7878
char err_buf[2048] = {0};
7979
int len = 0;
8080
len += snprintf(err_buf+len,2040-len,"Failed to compile regular expression: %s with error: ", re);
81-
regerror(rc, &myregex, err_buf+len, 2048-len);
81+
len += regerror(rc, &myregex, err_buf+len, 2048-len);
8282
regfree(&myregex);
8383
if (maxn) {
8484
outMatches[0] = mystrdup(err_buf);

0 commit comments

Comments
 (0)