diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index bf4ba9fd16..02b7e11b27 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -459,15 +459,14 @@ DEF_CONSOLE_CMD(ConSave) } if (argc == 2) { - char *filename = str_fmt("%s.sav", argv[1]); + std::string filename = stdstr_fmt("%s.sav", argv[1]); IConsolePrint(CC_DEFAULT, "Saving map..."); if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) { IConsolePrint(CC_ERROR, "Saving map failed"); } else { - IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename); + IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename.c_str()); } - free(filename); return true; } diff --git a/src/debug.cpp b/src/debug.cpp index 462e969be4..593b8e9b6e 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -173,18 +173,16 @@ void debug_print(const char *dbg, const char *buf) have_inited = true; unsigned int num = 0; int pid = getpid(); - const char *fn = nullptr; for(;;) { free(fn); - fn = str_fmt("random-out-%d-%u.log", pid, num); - f = FioFOpenFile(fn, "wx", AUTOSAVE_DIR); + std::string fn = stdstr_fmt("random-out-%d-%u.log", pid, num); + f = FioFOpenFile(fn.c_str(), "wx", AUTOSAVE_DIR); if (f == nullptr && errno == EEXIST) { num++; continue; } break; } - free(fn); } #else static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR); diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index 3d4213e25e..da0cb00d4d 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -34,26 +34,23 @@ template void DumpState(Tpf &pf1, Tpf &pf2) #if defined(UNIX) && defined(__GLIBC__) static unsigned int num = 0; int pid = getpid(); - const char *fn1 = nullptr; - const char *fn2 = nullptr; + std::string fn1; + std::string fn2; FILE *f1 = nullptr; FILE *f2 = nullptr; for(;;) { - free(fn1); - fn1 = str_fmt("yapf-%d-%u-1.txt", pid, num); - f1 = fopen(fn1, "wx"); + fn1 = stdstr_fmt("yapf-%d-%u-1.txt", pid, num); + f1 = fopen(fn1.c_str(), "wx"); if (f1 == nullptr && errno == EEXIST) { num++; continue; } - fn2 = str_fmt("yapf-%d-%u-2.txt", pid, num); - f2 = fopen(fn2, "w"); + fn2 = stdstr_fmt("yapf-%d-%u-2.txt", pid, num); + f2 = fopen(fn2.c_str(), "w"); num++; break; } - DEBUG(desync, 0, "Dumping YAPF state to %s and %s", fn1, fn2); - free(fn1); - free(fn2); + DEBUG(desync, 0, "Dumping YAPF state to %s and %s", fn1.c_str(), fn2.c_str()); #else FILE *f1 = fopen("yapf1.txt", "wt"); FILE *f2 = fopen("yapf2.txt", "wt"); diff --git a/src/string.cpp b/src/string.cpp index e6ccc68c43..d5939ce885 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -138,30 +138,6 @@ char *stredup(const char *s, const char *last) return tmp; } -char *str_vfmt(const char *str, va_list va) -{ - char buf[4096]; - - int len = vseprintf(buf, lastof(buf), str, va); - char *p = MallocT(len + 1); - memcpy(p, buf, len + 1); - return p; -} - -/** - * Format, "printf", into a newly allocated string. - * @param str The formatting string. - * @return The formatted string. You must free this! - */ -char *CDECL str_fmt(const char *str, ...) -{ - va_list va; - va_start(va, str); - char *output = str_vfmt(str, va); - va_end(va); - return output; -} - std::string stdstr_vfmt(const char *str, va_list va) { char buf[4096]; diff --git a/src/string_func.h b/src/string_func.h index 9f64e6b398..16c8c3c0a6 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -37,8 +37,6 @@ char *stredup(const char *src, const char *last = nullptr) NOACCESS(2); int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FORMAT(3, 4) NOACCESS(2); int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap) WARN_FORMAT(3, 0) NOACCESS(2); -char *CDECL str_fmt(const char *str, ...) WARN_FORMAT(1, 2); -char *str_vfmt(const char *str, va_list ap) WARN_FORMAT(1, 0); std::string CDECL stdstr_fmt(const char *str, ...) WARN_FORMAT(1, 2); std::string stdstr_vfmt(const char *str, va_list va) WARN_FORMAT(1, 0);