mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
fix(file): SMem* should be used to allocate StreamRecords with all bytes zeroed
This commit is contained in:
parent
87a8d3f643
commit
4bea27d25e
2 changed files with 10 additions and 8 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
#include "bc/Debug.hpp"
|
#include "bc/Debug.hpp"
|
||||||
#include "bc/File.hpp"
|
#include "bc/File.hpp"
|
||||||
#include "bc/Memory.hpp"
|
#include "bc/Memory.hpp"
|
||||||
|
#include "bc/memory/Storm.hpp"
|
||||||
#include "bc/String.hpp"
|
#include "bc/String.hpp"
|
||||||
#include "bc/system/file/posix/Support.hpp"
|
#include "bc/system/file/posix/Support.hpp"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
@ -54,7 +55,7 @@ bool Close(FileParms* parms) {
|
||||||
BLIZZARD_ASSERT(file != nullptr);
|
BLIZZARD_ASSERT(file != nullptr);
|
||||||
|
|
||||||
::close(file->filefd);
|
::close(file->filefd);
|
||||||
Blizzard::Memory::Free(file);
|
SMemFree(file);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -652,7 +653,7 @@ bool Open(FileParms* parms) {
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
auto namelength = Blizzard::String::Length(name.ToString()) + 1;
|
auto namelength = Blizzard::String::Length(name.ToString()) + 1;
|
||||||
file = reinterpret_cast<Blizzard::File::StreamRecord*>(Blizzard::Memory::Allocate(sizeof(Blizzard::File::StreamRecord) + namelength));
|
file = reinterpret_cast<Blizzard::File::StreamRecord*>(SMemAlloc(sizeof(Blizzard::File::StreamRecord) + namelength, __FILE__, __LINE__, 0x8));
|
||||||
auto filename = reinterpret_cast<char*>(file) + sizeof(Blizzard::File::StreamRecord);
|
auto filename = reinterpret_cast<char*>(file) + sizeof(Blizzard::File::StreamRecord);
|
||||||
file->name = filename;
|
file->name = filename;
|
||||||
Blizzard::String::Copy(filename, name.ToString(), namelength);
|
Blizzard::String::Copy(filename, name.ToString(), namelength);
|
||||||
|
|
@ -663,9 +664,10 @@ bool Open(FileParms* parms) {
|
||||||
file->haveinfo = false;
|
file->haveinfo = false;
|
||||||
file->mode = parms->mode;
|
file->mode = parms->mode;
|
||||||
|
|
||||||
// if (!file->unk48 || !*file->unk48) {
|
// TODO: this part is likely GetFileInfoByFile
|
||||||
file->info.size = info.st_size;
|
if (!file->unk48 || !*file->unk48) {
|
||||||
// }
|
file->info.size = info.st_size;
|
||||||
|
}
|
||||||
|
|
||||||
auto modtime = Blizzard::Time::FromUnixTime(info.st_mtime);
|
auto modtime = Blizzard::Time::FromUnixTime(info.st_mtime);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "bc/Unicode.hpp"
|
#include "bc/Unicode.hpp"
|
||||||
#include "bc/File.hpp"
|
#include "bc/File.hpp"
|
||||||
#include "bc/time/Time.hpp"
|
#include "bc/time/Time.hpp"
|
||||||
|
#include "bc/memory/Storm.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
@ -208,8 +209,7 @@ bool Close(FileParms* parms) {
|
||||||
::CloseHandle(file->filehandle);
|
::CloseHandle(file->filehandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Blizzard::Memory::Free(file);
|
SMemFree(file);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -676,7 +676,7 @@ bool Open(FileParms* parms) {
|
||||||
// alloc(sizeof(StreamRecord) + len(name) + 1)
|
// alloc(sizeof(StreamRecord) + len(name) + 1)
|
||||||
// block of memory holds file as well as C string of the filename
|
// block of memory holds file as well as C string of the filename
|
||||||
auto namesize = Blizzard::String::Length(name);
|
auto namesize = Blizzard::String::Length(name);
|
||||||
file = reinterpret_cast<Blizzard::File::StreamRecord*>(Blizzard::Memory::Allocate(sizeof(Blizzard::File::StreamRecord) + 1 + namesize));
|
file = reinterpret_cast<Blizzard::File::StreamRecord*>(SMemAlloc(sizeof(Blizzard::File::StreamRecord) + 1 + namesize, __FILE__, __LINE__, 0x8));
|
||||||
// set the name pointer inside of StreamRecord to point to the end of StreamRecord (i.e. the start of the name cstring in the memory block)
|
// set the name pointer inside of StreamRecord to point to the end of StreamRecord (i.e. the start of the name cstring in the memory block)
|
||||||
auto filename = reinterpret_cast<char*>(file) + sizeof(Blizzard::File::StreamRecord);
|
auto filename = reinterpret_cast<char*>(file) + sizeof(Blizzard::File::StreamRecord);
|
||||||
file->name = filename;
|
file->name = filename;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue