]> granicus.if.org Git - nethack/commitdiff
strdup vs dupstr
authorPatR <rankin@nethack.org>
Thu, 10 Feb 2022 18:25:25 +0000 (10:25 -0800)
committerPatR <rankin@nethack.org>
Thu, 10 Feb 2022 18:25:25 +0000 (10:25 -0800)
mdlib.c was avoiding alloc() and dupstr() because mdlib.o gets linked
with makedefs and makedefs used to need to avoid those.  But makedefs
doesn't avoid those anymore, so mdlib.c doesn't need to either.

Replace a couple of other strdup() calls in other files too.

src/files.c
src/mdlib.c
src/pline.c

index 55397a61d2637de6be81404898858fa14e577864..cb47ad4f0a0dbd34f813f3adcee3a71690fbc487 100644 (file)
@@ -1217,7 +1217,7 @@ get_saved_games(void)
             if (findfirst((char *) fq_save)) {
                 i = 0;
                 do {
-                    files[i++] = strdup(foundfile);
+                    files[i++] = dupstr(foundfile);
                 } while (findnext());
             }
         }
index 31cdf17390affb3840406422223a791a9de2af83..633d0efe1e7bd69d488cac9463774937723ff0db 100644 (file)
@@ -14,9 +14,6 @@
 #ifndef MAKEDEFS_C
 #define MDLIB_C
 #include "config.h"
-#ifdef MONITOR_HEAP
-#undef free /* makedefs, mdlib don't use the alloc and free in src/alloc.c */
-#endif
 #include "permonst.h"
 #include "objclass.h"
 #include "sym.h"
@@ -644,7 +641,7 @@ opt_out_words(char *str,     /* input, but modified during processing */
         if (word)
             *word = '\0';
         if (*length_p + (int) strlen(str) > COLNO - 5) {
-            opttext[idxopttext] = strdup(optbuf);
+            opttext[idxopttext] = dupstr(optbuf);
             if (idxopttext < (MAXOPT - 1))
                 idxopttext++;
             Sprintf(optbuf, "%s", opt_indent),
@@ -670,7 +667,7 @@ build_options(void)
 #endif
 #endif
     build_savebones_compat_string();
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
 #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
@@ -684,11 +681,11 @@ build_options(void)
 #endif /* NH_DEVEL_STATUS == NH_STATUS_RELEASED */
     Sprintf(optbuf, "%sNetHack version %d.%d.%d%s\n",
             opt_indent, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, STATUS_ARG);
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     Sprintf(optbuf, "Options compiled into this edition:");
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     optbuf[0] = '\0';
@@ -706,17 +703,17 @@ build_options(void)
                (i < SIZE(build_opts) - 1) ? "," : ".");
         opt_out_words(buf, &length);
     }
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     optbuf[0] = '\0';
     winsyscnt = count_and_validate_winopts();
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     Sprintf(optbuf, "Supported windowing system%s:",
             (winsyscnt > 1) ? "s" : "");
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     optbuf[0] = '\0';
@@ -748,7 +745,7 @@ build_options(void)
         opt_out_words(buf, &length);
     }
 
-    opttext[idxopttext] = strdup(optbuf);
+    opttext[idxopttext] = dupstr(optbuf);
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     optbuf[0] = '\0';
@@ -776,7 +773,7 @@ build_options(void)
         /* add lua copyright notice;
            ":TAG:" substitutions are deferred to caller */
         for (i = 0; lua_info[i]; ++i) {
-            opttext[idxopttext] = strdup(lua_info[i]);
+            opttext[idxopttext] = dupstr(lua_info[i]);
             if (idxopttext < (MAXOPT - 1))
                 idxopttext++;
         }
@@ -784,7 +781,7 @@ build_options(void)
 #endif /* MAKEDEFS_C || FOR_RUNTIME */
 
     /* end with a blank line */
-    opttext[idxopttext] = strdup("");
+    opttext[idxopttext] = dupstr("");
     if (idxopttext < (MAXOPT - 1))
         idxopttext++;
     return;
index 17d472006d5c1c217172acb67d57d7ad2670386e..89b175566c593a2efb92dfd6b073813fd21ef5b0 100644 (file)
@@ -406,10 +406,10 @@ gamelog_add(unsigned int glflags, long gltime, const char *str)
     struct gamelog_line *tmp;
     struct gamelog_line *lst = g.gamelog;
 
-    tmp = (struct gamelog_line *)alloc(sizeof(struct gamelog_line));
+    tmp = (struct gamelog_line *) alloc(sizeof (struct gamelog_line));
     tmp->turn = gltime;
     tmp->flags = glflags;
-    tmp->text = strdup(str);
+    tmp->text = dupstr(str);
     tmp->next = NULL;
     while (lst && lst->next)
         lst = lst->next;
@@ -420,7 +420,7 @@ gamelog_add(unsigned int glflags, long gltime, const char *str)
 }
 
 void
-livelog_printf(unsigned int ll_type, const char *line, ...)
+livelog_printf(unsigned ll_type, const char *line, ...)
 {
     char gamelogbuf[BUFSZ * 2];
     va_list the_args;
@@ -435,16 +435,20 @@ livelog_printf(unsigned int ll_type, const char *line, ...)
 }
 
 #else
+
 void
-gamelog_add(unsigned int glflags UNUSED, long gltime UNUSED, const char *msg UNUSED)
+gamelog_add(
+    unsigned glflags UNUSED, long gltime UNUSED, const char *msg UNUSED)
 {
-    /* nothing here */
+    /* nothing here */
 }
+
 void
-livelog_printf(unsigned int ll_type UNUSED, const char *line UNUSED, ...)
+livelog_printf(unsigned ll_type UNUSED, const char *line UNUSED, ...)
 {
-    /* nothing here */
+    /* nothing here */
 }
+
 #endif /* !CHRONICLE */
 
 static void vraw_printf(const char *, va_list);