diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-25 03:23:56 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-25 03:23:56 +0200 |
commit | 69fc595053d2075d6a7d99d94912156851a0221d (patch) | |
tree | 438e6763e478f3f65d65d94e780b53e29debd674 /c | |
parent | 87f8d4ade699911717c4c9454a495b2eb630b4c6 (diff) | |
download | EpisodeBrowser-69fc595053d2075d6a7d99d94912156851a0221d.tar.gz |
Fix FileView::Initialized bug.
The bug doesn't appear with MinGW GCC, but when compiled with Visual Studio, the prorgam would perform a read access violation.
Diffstat (limited to 'c')
-rw-r--r-- | c/data.h | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -84,20 +84,21 @@ struct FileView static FileView Initialized(const wchar_t* filename, size_t c, size_t cInit = 0) { - bool bExisting = GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES; - FileView fv(filename, c); - /* If file didn't exist, initialize it with defaults. */ - if (!bExisting) { + if (cInit && GetFileAttributes(filename) == INVALID_FILE_ATTRIBUTES) { + FileView fv(filename, c); T t; cInit = cInit? cInit: c; for (size_t i = 0; i < cInit; i++) memcpy(fv+i, &t, sizeof(T)); } - return fv; + return { filename, c }; } + FileView(FileView<T>&) = delete; + FileView(FileView<T>&& fv) = delete; + FileView(const wchar_t* filename, size_t c) : c(c) { hf = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, |