From 379875dff028028cd206482a2042a252fbb8ff48 Mon Sep 17 00:00:00 2001 From: gaozheng Date: Tue, 23 Jun 2026 10:10:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(io/gpr):=20traces/=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=94=B9=2064=20=E4=BD=8D=E9=98=B2=E6=BA=A2?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MSVC 的 long 是 32 位,samples*traces 大体下会溢出。 BScan.traces 改 std::int64_t;大小校验 expected 与 data 分配均在 64 位域计算,为后续整卷(数十亿体素)立纪律。 --- src/io/gpr/IprbReader.cpp | 10 +++++----- src/io/gpr/IprbReader.hpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/io/gpr/IprbReader.cpp b/src/io/gpr/IprbReader.cpp index a41541d..4441753 100644 --- a/src/io/gpr/IprbReader.cpp +++ b/src/io/gpr/IprbReader.cpp @@ -13,9 +13,9 @@ BScan readIprb(const std::string& path, const IprHeader& h) { } const std::streamsize fileSize = f.tellg(); - const long traces = h.lastTrace + 1; - const long count = static_cast(h.samples) * traces; - const std::streamsize expected = static_cast(count) * 2; + const std::int64_t traces = static_cast(h.lastTrace) + 1; + const std::int64_t count = static_cast(h.samples) * traces; + const std::int64_t expected = count * 2; if (fileSize != expected) { throw std::runtime_error("readIprb: 文件大小与 samples*traces*2 不符: " + path); } @@ -23,10 +23,10 @@ BScan readIprb(const std::string& path, const IprHeader& h) { BScan b; b.samples = h.samples; b.traces = traces; - b.data.resize(static_cast(count)); + b.data.resize(static_cast(h.samples) * traces); f.seekg(0, std::ios::beg); - f.read(reinterpret_cast(b.data.data()), expected); + f.read(reinterpret_cast(b.data.data()), static_cast(expected)); if (!f) { throw std::runtime_error("readIprb: 读取数据失败: " + path); } diff --git a/src/io/gpr/IprbReader.hpp b/src/io/gpr/IprbReader.hpp index 90aa5b5..c6edc29 100644 --- a/src/io/gpr/IprbReader.hpp +++ b/src/io/gpr/IprbReader.hpp @@ -12,7 +12,7 @@ namespace geopro::io::gpr { // 一个通道一条测线的雷达 B-scan 剖面(int16 存储,布局 [trace*samples + s],s 最快)。 struct BScan { int samples = 0; - long traces = 0; + std::int64_t traces = 0; std::vector data; // 大小 = samples*traces };