]> granicus.if.org Git - nethack/commitdiff
Revert "follow-up: use only the memory that's required"
authornhmall <nhmall@nethack.org>
Fri, 1 Jul 2022 02:38:14 +0000 (22:38 -0400)
committernhmall <nhmall@nethack.org>
Fri, 1 Jul 2022 02:38:14 +0000 (22:38 -0400)
This reverts commit 4a0654c70875964fbe769165e04aebe2713cbe34.

sys/share/cppregex.cpp

index 9f95c6274559569d6ad2f27804eded64fac163c4..0e3a7de1a923d16a3c25b827a5c7f14a85f91c46 100644 (file)
@@ -12,7 +12,7 @@ extern "C" {
   #include <hack.h>
 
   extern const char regex_id[] = "cppregex";
-  static char *cppregex_static_buffer = (char *) 0;
+  static char cppregex_static_buffer[BUFSZ];
 
   struct nhregex {
     std::unique_ptr<std::regex> 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;