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());