diff --git a/src/backend/regex/regc_nfa.c b/src/backend/regex/regc_nfa.c index 92c9c4d795d..3c65d97de1b 100644 --- a/src/backend/regex/regc_nfa.c +++ b/src/backend/regex/regc_nfa.c @@ -1994,9 +1994,12 @@ fixempties(struct nfa *nfa, * current target state. totalinarcs is probably a considerable * overestimate of the space needed, but the NFA is unlikely to be large * enough at this point to make it worth being smarter. + * + * Note: totalinarcs could be zero, and some machines return NULL for + * malloc(0). Don't throw an error if so. */ arcarray = (struct arc **) MALLOC(totalinarcs * sizeof(struct arc *)); - if (arcarray == NULL) + if (arcarray == NULL && totalinarcs != 0) { NERR(REG_ESPACE); FREE(inarcsorig);