From 42caec7e58bbae890b923932a8e98eb1d6785908 Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 22 Aug 2022 01:24:49 +0000 Subject: [PATCH] Use std::span for pof reading functions --- similar/main/polyobj.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/similar/main/polyobj.cpp b/similar/main/polyobj.cpp index 575e3c4cd..f663cf5ab 100644 --- a/similar/main/polyobj.cpp +++ b/similar/main/polyobj.cpp @@ -24,6 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ +#include #include #include #include @@ -80,16 +81,17 @@ static void _pof_cfseek(int len,int type) #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type)) -static int pof_read_int(const uint8_t *bufp) +static int pof_read_int(const std::span bufp) { - const auto r = GET_INTEL_INT(&bufp[Pof_addr]); + const auto s = bufp.subspan(Pof_addr, 4); Pof_addr += 4; + const auto r = GET_INTEL_INT(s.data()); return r; } -static size_t pof_cfread(void *const dst, const size_t elsize, const uint8_t *bufp) +static size_t pof_cfread(void *const dst, const size_t elsize, const std::span bufp) { - if (Pof_addr + elsize > Pof_file_end) + if (Pof_addr + elsize > bufp.size()) return 0; memcpy(dst, &bufp[Pof_addr], elsize); @@ -103,14 +105,15 @@ static size_t pof_cfread(void *const dst, const size_t elsize, const uint8_t *bu #define new_pof_read_int(i,f) pof_cfread(&(i), sizeof(i), (f)) -static short pof_read_short(const uint8_t *bufp) +static short pof_read_short(const std::span bufp) { - const auto r = GET_INTEL_SHORT(&bufp[Pof_addr]); + const auto s = bufp.subspan(Pof_addr, 2); Pof_addr += 2; + const auto r = GET_INTEL_SHORT(s.data()); return r; } -static void pof_read_string(char *buf,int max_char, ubyte *bufp) +static void pof_read_string(char *buf,int max_char, const std::span bufp) { for (int i=0; i bufp) { vec.x = pof_read_int(bufp); vec.y = pof_read_int(bufp); @@ -130,7 +133,7 @@ static void pof_read_vec(vms_vector &vec, const uint8_t *bufp) Int3(); } -static void pof_read_ang(vms_angvec &ang, const uint8_t *bufp) +static void pof_read_ang(vms_angvec &ang, const std::span bufp) { ang.p = pof_read_short(bufp); ang.b = pof_read_short(bufp);