From 14d1a4666d5f6d3547c2b57922dfdae2f2656883 Mon Sep 17 00:00:00 2001 From: Ondrej Novak Date: Sat, 15 Feb 2025 13:10:17 +0100 Subject: [PATCH] fix issue reported by msvc memory sanitiser --- game/interfac.c | 2 +- game/skeldal.c | 2 +- game/temp_storage.cpp | 14 +++++--------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/game/interfac.c b/game/interfac.c index f632110..12283bd 100644 --- a/game/interfac.c +++ b/game/interfac.c @@ -1386,7 +1386,7 @@ void enc_close(TMPFILE_RD *fil) int load_string_list_ex(TSTR_LIST *list,const char *filename) { char c[1024],*p; - int i,j,lin=0; + int i=0,j,lin=0; TMPFILE_RD *f; f=enc_open(filename); diff --git a/game/skeldal.c b/game/skeldal.c index 581d02a..97fb75e 100644 --- a/game/skeldal.c +++ b/game/skeldal.c @@ -385,7 +385,7 @@ const void *load_mob_legacy_format(const void *p, int32_t *s) { nx = offsetof(TMOB, dialog_flags); memmove(d, c, nx - ofs); c+=nx - ofs -1; //second padding 1 - d+=nx; + d+=nx-ofs; ofs=nx; nx = sizeof(TMOB); memmove(d, c, nx - ofs - 1); //last padding 1 diff --git a/game/temp_storage.cpp b/game/temp_storage.cpp index 853b69e..9cf329b 100644 --- a/game/temp_storage.cpp +++ b/game/temp_storage.cpp @@ -11,11 +11,11 @@ extern "C" { } typedef struct _temp_storage_file_wr { - std::vector *_data; + std::string *_data; } TMPFILE_WR; typedef struct _temp_storage_file_rd { - std::basic_string_view _data; + std::string_view _data; int skp = 0; } TMPFILE_RD; @@ -31,7 +31,7 @@ struct icompare { } }; -using FileSystem = std::map, icompare >; +using FileSystem = std::map; static FileSystem temp_fsystem; @@ -40,8 +40,6 @@ void temp_storage_store(const char *name, const void *data, int32_t size) { auto e = b+size; auto &v =temp_fsystem[std::string(name)]; v.clear(); - v.resize(size+1); - v[size] = 0; v.resize(size); std::copy(b,e, v.begin()); } @@ -74,9 +72,7 @@ void temp_storage_clear() { TMPFILE_RD* temp_storage_open(const char *name) { auto iter = temp_fsystem.find(std::string_view(name)); if (iter == temp_fsystem.end()) return NULL; - iter->second.push_back(0); //put extra zero at the end - iter->second.resize(iter->second.size()-1); - return new TMPFILE_RD{std::basic_string_view(iter->second.data(), iter->second.size())}; + return new TMPFILE_RD{{iter->second.c_str(), iter->second.size()}}; } TMPFILE_WR* temp_storage_create(const char *name) { @@ -164,5 +160,5 @@ int temp_storage_internal_end_scanf(TMPFILE_RD *f, int r) { } void temp_storage_ungetc(TMPFILE_RD *f) { - f->_data = std::basic_string_view(f->_data.data()-1, f->_data.size()+1); + f->_data = {f->_data.data()-1, f->_data.size()+1}; }