From bd351b055fcd8ac60cb43dbb29c970044f011ef8 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 18 Sep 2023 23:00:43 +0800 Subject: [PATCH] fix a bug of reading CRLF file on win32 --- build.ps1 | 3 +++ src/io.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/build.ps1 b/build.ps1 index aca5ca1e..3b794a76 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,3 +1,6 @@ +if (Test-Path build) { + Remove-Item -Recurse -Force build +} mkdir build cd build cmake .. diff --git a/src/io.cpp b/src/io.cpp index 4ece9df1..500e4638 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -58,6 +58,9 @@ Bytes _default_import_handler(const Str& name){ std::vector buffer(ftell(io.fp)); fseek(io.fp, 0, SEEK_SET); size_t sz = io_fread(buffer.data(), 1, buffer.size(), io.fp); + PK_ASSERT(sz <= buffer.size()); + // in text mode, CR may be dropped, which may cause `sz < buffer.size()` + if(sz < buffer.size()) buffer.resize(sz); PK_UNUSED(sz); Bytes b(std::move(buffer)); if(io.is_text()) return VAR(b.str());