From e097571653f6aabe3b7a34d025fde58bef340fc4 Mon Sep 17 00:00:00 2001 From: AJR Date: Tue, 24 Dec 2024 09:24:28 -0500 Subject: formats/fs_vtech.cpp: Fix off-by-one error: end address is exclusive, not inclusive --- src/lib/formats/fs_vtech.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/formats/fs_vtech.cpp b/src/lib/formats/fs_vtech.cpp index 03ceffbab5b..6b414518437 100644 --- a/src/lib/formats/fs_vtech.cpp +++ b/src/lib/formats/fs_vtech.cpp @@ -19,7 +19,7 @@ namespace fs { const vtech_image VTECH; } // Filesystem has no subdirectories. // // Track 0 sectors 0-14 have the file names. 16 bytes/entry -// offset 0 : File type 'T' (basic) or 'B' (binary) +// offset 0 : File type 'T' (basic), 'B' (binary), or some other letter (application-specific) // offset 1 : 0x3a // offset 2-9: File name // offset a : Track number of first file sector @@ -147,7 +147,7 @@ meta_data vtech_impl::file_metadata(const u8 *entry) res.set(meta_name::name, trim_end_spaces(rstr(entry+2, 8))); res.set(meta_name::file_type, std::string{ char(entry[0]) }); res.set(meta_name::loading_address, get_u16le(entry + 0xc)); - res.set(meta_name::length, ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff)); + res.set(meta_name::length, (get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff); return res; } @@ -280,7 +280,7 @@ err_t vtech_impl::file_create(const std::vector &path, const meta_d bdir.w8 (off+0xa, 0x00); bdir.w8 (off+0xb, 0x00); bdir.w16l(off+0xc, meta.get_number(meta_name::loading_address, 0x7ae9)); - bdir.w16l(off+0xe, bdir.r16l(off+0xc) - 1); // Size 0 initially + bdir.w16l(off+0xe, bdir.r16l(off+0xc)); // Size 0 initially return ERR_OK; } } @@ -303,7 +303,7 @@ std::pair> vtech_impl::file_read(const std::vector &path, const std::ve u8 *entry = bdir.data() + off; - u32 cur_len = ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff); + u32 cur_len = (get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff; u32 new_len = data.size(); if(new_len > 65535) new_len = 65535; @@ -372,7 +372,7 @@ err_t vtech_impl::file_write(const std::vector &path, const std::ve dblk.w16l(126, 0); } - u16 end_address = (get_u16le(entry + 0xc) + data.size() - 1) & 0xffff; + u16 end_address = (get_u16le(entry + 0xc) + data.size()) & 0xffff; put_u16le(entry + 0xe, end_address); if(need_ns) { entry[0xa] = blocks[0].first; -- cgit v1.2.3