From ca3e3ed12c803a73d28473a941560c269487db75 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Wed, 13 Mar 2024 10:39:21 +0100
Subject: [PATCH] Fix decompression for sparc compiler

---
 lib/decompress/read_bitstream.h | 8 +++++++-
 test/cmp_decmp/test_cmp_decmp.c | 9 ++++-----
 test/test_common/test_common.c  | 1 +
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/decompress/read_bitstream.h b/lib/decompress/read_bitstream.h
index c65090e..f46804c 100644
--- a/lib/decompress/read_bitstream.h
+++ b/lib/decompress/read_bitstream.h
@@ -106,8 +106,15 @@ static const uint32_t BIT_MASK[] = {
 
 static __inline uint64_t bit_read_unaligned_64be(const void *ptr)
 {
+#ifdef __sparc__
+	uint64_t v;
+	memcpy(&v, ptr, sizeof(v));
+	return cpu_to_be64(v);
+
+#else
 	typedef __attribute__((aligned(1))) uint64_t unalign64;
 	return cpu_to_be64(*(const unalign64*)ptr);
+#endif
 }
 
 
@@ -184,7 +191,6 @@ static __inline size_t bit_init_decoder(struct bit_decoder *dec, const void *buf
  *
  * @returns extracted value
  */
-
 static __inline uint64_t bit_peek_bits(const struct bit_decoder *dec, unsigned int nb_bits)
 {
 	/* mask for the shift value register to prevent undefined behaviour */
diff --git a/test/cmp_decmp/test_cmp_decmp.c b/test/cmp_decmp/test_cmp_decmp.c
index ae53c8a..ead45c4 100644
--- a/test/cmp_decmp/test_cmp_decmp.c
+++ b/test/cmp_decmp/test_cmp_decmp.c
@@ -53,7 +53,7 @@ void setUp(void)
 	uint64_t seed;
 	static int n;
 
-#if HAS_TIME_H
+#ifdef HAS_TIME_H
 	seed = (uint64_t)(time(NULL) ^ getpid()  ^ (intptr_t)&setUp);
 #else
 	seed = 1;
@@ -968,16 +968,15 @@ static int32_t chunk_round_trip(void *data, uint32_t data_size,
  * @test decompress_cmp_entiy
  */
 
-
-void test_random_chunk_round_trip(void)
+void test_random_collection_round_trip(void)
 {
 	enum cmp_data_type data_type;
 	enum cmp_mode cmp_mode;
-	enum { MAX_DATA_TO_COMPRESS_SIZE = CMP_ENTITY_MAX_ORIGINAL_SIZE};
+	enum { MAX_DATA_TO_COMPRESS_SIZE = UINT16_MAX};
+	uint32_t cmp_data_capacity = COMPRESS_CHUNK_BOUND(MAX_DATA_TO_COMPRESS_SIZE, 1);
 	void *data = malloc(CMP_ENTITY_MAX_ORIGINAL_SIZE);
 	void *model = malloc(MAX_DATA_TO_COMPRESS_SIZE);
 	void *updated_model = calloc(1, MAX_DATA_TO_COMPRESS_SIZE);
-	uint32_t cmp_data_capacity = CMP_ENTITY_MAX_SIZE-NON_IMAGETTE_HEADER_SIZE;
 	void *cmp_data = malloc(cmp_data_capacity);
 
 	for (data_type = 1; data_type <= DATA_TYPE_F_CAM_BACKGROUND; data_type++) {
diff --git a/test/test_common/test_common.c b/test/test_common/test_common.c
index b2be771..4f90832 100644
--- a/test/test_common/test_common.c
+++ b/test/test_common/test_common.c
@@ -1,4 +1,5 @@
 #include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
-- 
GitLab