From: nhmall Date: Fri, 1 Jul 2022 02:38:14 +0000 (-0400) Subject: Revert "follow-up: use only the memory that's required" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=751b6e646f341e1d201f1a98770470c23db9e6b7;p=nethack Revert "follow-up: use only the memory that's required" This reverts commit 4a0654c70875964fbe769165e04aebe2713cbe34. --- diff --git a/sys/share/cppregex.cpp b/sys/share/cppregex.cpp index 9f95c6274..0e3a7de1a 100644 --- a/sys/share/cppregex.cpp +++ b/sys/share/cppregex.cpp @@ -12,7 +12,7 @@ extern "C" { #include extern const char regex_id[] = "cppregex"; - static char *cppregex_static_buffer = (char *) 0; + static char cppregex_static_buffer[BUFSZ]; struct nhregex { std::unique_ptr re; @@ -41,9 +41,8 @@ extern "C" { const char *regex_error_desc(struct nhregex *re) { if (re->err) { - if (cppregex_static_buffer != 0) - free(cppregex_static_buffer); - cppregex_static_buffer = dupstr(re->err->what()); + Snprintf(cppregex_static_buffer, sizeof cppregex_static_buffer, + "%s", re->err->what()); return cppregex_static_buffer; } else return nullptr;