]> granicus.if.org Git - nethack/commitdiff
fix for onefile FITSint, FITSuint
authorPatR <rankin@nethack.org>
Sat, 7 Jan 2023 20:48:10 +0000 (12:48 -0800)
committerPatR <rankin@nethack.org>
Sat, 7 Jan 2023 20:48:10 +0000 (12:48 -0800)
I assumed that the complaint about macro refinition was for the two
in alloc.c replacing two from hack.h from another file, but it could
be that those being defined by alloc.c were interferring with the
regular hack.h ones.  alloc.c doesn't need them, and was also skipping
an opportunity to use one of them.

src/alloc.c

index ad477bd308cf89e32a998e82c5e04aa5f6ef4364..28023cafbf9f5e1d4692b6d408617755caa47ceb 100644 (file)
@@ -14,9 +14,9 @@
 #include "nhlua.h"
 #endif
 
-#define FITSint(x) FITSint_(x, __func__, (int) __LINE__)
+/*#define FITSint(x) FITSint_(x, __func__, (int) __LINE__)*/
 extern int FITSint_(LUA_INTEGER, const char *, int);
-#define FITSuint(x) FITSuint_(x, __func__, (int) __LINE__)
+/*#define FITSuint(x) FITSuint_(x, __func__, (int) __LINE__)*/
 extern unsigned FITSuint_(unsigned long long, const char *, int);
 
 char *fmt_ptr(const genericptr) NONNULL;
@@ -182,7 +182,10 @@ nhfree(genericptr_t ptr, const char *file, int line)
 char *
 nhdupstr(const char *string, const char *file, int line)
 {
-    return strcpy((char *) nhalloc(strlen(string) + 1, file, line), string);
+    /* we've got some info about the caller, so use it instead of __func__ */
+    unsigned len = FITSuint_(strlen(string), file, line);
+
+    return strcpy((char *) nhalloc(len + 1, file, line), string);
 }
 #undef dupstr
 
@@ -194,7 +197,8 @@ nhdupstr(const char *string, const char *file, int line)
 char *
 dupstr(const char *string)
 {
-    unsigned len = FITSuint(strlen(string));
+    unsigned len = FITSuint_(strlen(string), __func__, (int) __LINE__);
+
     return strcpy((char *) alloc(len + 1), string);
 }