fix issue reported by msvc memory sanitiser

This commit is contained in:
Ondrej Novak 2025-02-15 13:10:17 +01:00
parent 075100d2ce
commit 14d1a4666d
3 changed files with 7 additions and 11 deletions

View file

@ -1386,7 +1386,7 @@ void enc_close(TMPFILE_RD *fil)
int load_string_list_ex(TSTR_LIST *list,const char *filename) int load_string_list_ex(TSTR_LIST *list,const char *filename)
{ {
char c[1024],*p; char c[1024],*p;
int i,j,lin=0; int i=0,j,lin=0;
TMPFILE_RD *f; TMPFILE_RD *f;
f=enc_open(filename); f=enc_open(filename);

View file

@ -385,7 +385,7 @@ const void *load_mob_legacy_format(const void *p, int32_t *s) {
nx = offsetof(TMOB, dialog_flags); nx = offsetof(TMOB, dialog_flags);
memmove(d, c, nx - ofs); memmove(d, c, nx - ofs);
c+=nx - ofs -1; //second padding 1 c+=nx - ofs -1; //second padding 1
d+=nx; d+=nx-ofs;
ofs=nx; ofs=nx;
nx = sizeof(TMOB); nx = sizeof(TMOB);
memmove(d, c, nx - ofs - 1); //last padding 1 memmove(d, c, nx - ofs - 1); //last padding 1

View file

@ -11,11 +11,11 @@ extern "C" {
} }
typedef struct _temp_storage_file_wr { typedef struct _temp_storage_file_wr {
std::vector<uint8_t> *_data; std::string *_data;
} TMPFILE_WR; } TMPFILE_WR;
typedef struct _temp_storage_file_rd { typedef struct _temp_storage_file_rd {
std::basic_string_view<uint8_t> _data; std::string_view _data;
int skp = 0; int skp = 0;
} TMPFILE_RD; } TMPFILE_RD;
@ -31,7 +31,7 @@ struct icompare {
} }
}; };
using FileSystem = std::map<std::string, std::vector<uint8_t>, icompare >; using FileSystem = std::map<std::string, std::string, icompare >;
static FileSystem temp_fsystem; 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 e = b+size;
auto &v =temp_fsystem[std::string(name)]; auto &v =temp_fsystem[std::string(name)];
v.clear(); v.clear();
v.resize(size+1);
v[size] = 0;
v.resize(size); v.resize(size);
std::copy(b,e, v.begin()); std::copy(b,e, v.begin());
} }
@ -74,9 +72,7 @@ void temp_storage_clear() {
TMPFILE_RD* temp_storage_open(const char *name) { TMPFILE_RD* temp_storage_open(const char *name) {
auto iter = temp_fsystem.find(std::string_view(name)); auto iter = temp_fsystem.find(std::string_view(name));
if (iter == temp_fsystem.end()) return NULL; if (iter == temp_fsystem.end()) return NULL;
iter->second.push_back(0); //put extra zero at the end return new TMPFILE_RD{{iter->second.c_str(), iter->second.size()}};
iter->second.resize(iter->second.size()-1);
return new TMPFILE_RD{std::basic_string_view<uint8_t>(iter->second.data(), iter->second.size())};
} }
TMPFILE_WR* temp_storage_create(const char *name) { 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) { void temp_storage_ungetc(TMPFILE_RD *f) {
f->_data = std::basic_string_view<uint8_t>(f->_data.data()-1, f->_data.size()+1); f->_data = {f->_data.data()-1, f->_data.size()+1};
} }