From 69fc595053d2075d6a7d99d94912156851a0221d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 25 Aug 2022 03:23:56 +0200 Subject: 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. --- c/data.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'c/data.h') diff --git a/c/data.h b/c/data.h index 1216359..7114440 100644 --- a/c/data.h +++ b/c/data.h @@ -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&) = delete; + FileView(FileView&& fv) = delete; + FileView(const wchar_t* filename, size_t c) : c(c) { hf = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, -- cgit v1.2.3