Const warnings (#98)
* Fix a warning lzp_upcast() discarding a const qualifier
GCC 13 warns:
src/libbz3.c:111:45: warning: passing argument 1 of 'lzp_upcast' discards 'const' qualifier from pointe
r target type [-Wdiscarded-qualifiers]
111 | if (heur > in && lzp_upcast(heur) != lzp_upcast(ref + (heur - in))) goto not_fo
und;
| ^~~~
src/libbz3.c:83:28: note: expected 'u8 *' {aka 'unsigned char *'} but argument is of type 'const u8 *'
{aka 'const unsigned char *'}
83 | static u32 lzp_upcast(u8 * ptr) {
| ~~~~~^~~
lzp_upcast() obviously does not modify the pointerd memory, hence this
patch fixes it by changing an lzp_upcast() prototype.
* Fix a const discard warning in lzp_decode_block()
GCC 13 warned:
src/libbz3.c:190:38: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
190 | if (oe > out_end) oe = out_end;
| ^
oe pointer is never dereferenced, hence this patch makes oe a pointer
to a constant data.diff --git a/src/libbz3.c b/src/libbz3.c
index fcb9996..d61f328 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -80,7 +80,7 @@ static u32 crc32sum(u32 crc, u8 * RESTRICT buf, size_t size) {
#define MATCH 0xf2
-static u32 lzp_upcast(u8 * ptr) {
+static u32 lzp_upcast(const u8 * ptr) {
// val = *(u32 *)ptr; - written this way to avoid UB
u32 val;
memcpy(&val, ptr, sizeof(val));
@@ -186,7 +186,7 @@ static s32 lzp_decode_block(const u8 * RESTRICT in, const u8 * in_end, s32 * RES
}
const u8 * ref = outs + val;
- u8 * oe = out + len;
+ const u8 * oe = out + len;
if (oe > out_end) oe = out_end;
while (out < oe) *out++ = *ref++;
