shithub: pokecrystal

Download patch

ref: 57a00f14d6997e0dbbf8070ecdc44f55f7ac192c
parent: a8b025291a642d3682305df2c09c03be69651af3
author: Jacob Moody <moody@posixcafe.org>
date: Tue Feb 28 15:56:38 EST 2023

more lzcomp port issues squashed

--- a/tools/lz/global.c
+++ b/tools/lz/global.c
@@ -3,10 +3,10 @@
 const struct compressor compressors[] = {
   // NOTE: the "flags" field for each compressor will be set to the chosen/current method number minus the base
   // number for that particular compressor. That means that each compressor will use a zero-based flags value.
-  {.methods = 72, .name = "singlepass",  .function = &try_compress_single_pass}, //  0-71
-  {.methods =  2, .name = "null",        .function = &store_uncompressed},       // 72-73
-  {.methods =  6, .name = "repetitions", .function = &try_compress_repetitions}, // 74-79
-  {.methods = 16, .name = "multipass",   .function = &try_compress_multi_pass},  // 80-95
+  {.methods = 72, .name = "singlepass",  .function = try_compress_single_pass}, //  0-71
+  {.methods =  2, .name = "null",        .function = store_uncompressed},       // 72-73
+  {.methods =  6, .name = "repetitions", .function = try_compress_repetitions}, // 74-79
+  {.methods = 16, .name = "multipass",   .function = try_compress_multi_pass},  // 80-95
   {0} // end of the list
 };
 
--- a/tools/lz/merging.c
+++ b/tools/lz/merging.c
@@ -1,18 +1,20 @@
 #include "proto.h"
 
 struct command * select_optimal_sequence (struct command ** sequences, const unsigned short * lengths, unsigned short * final_length) {
+  int _tmp;
   struct command * compressor_sequences[NUM_COMPRESSORS * 2];
   unsigned short compressor_lengths[NUM_COMPRESSORS * 2];
   struct command * inverted_sequences[COMPRESSION_METHODS];
   unsigned short inverted_lengths[COMPRESSION_METHODS];
-  unsigned p, current, method = 0;
+  unsigned int p, current, method = 0;
   for (current = 0; current < NUM_COMPRESSORS; current ++) {
     compressor_sequences[current] = select_command_sequence(sequences + method, lengths + method, compressors[current].methods, compressor_lengths + current);
-    compressor_sequences[current + NUM_COMPRESSORS] = select_command_sequence(sequences + method, lengths + method, -(int) compressors[current].methods,
+    _tmp = compressors[current].methods;
+    compressor_sequences[current + NUM_COMPRESSORS] = select_command_sequence(sequences + method, lengths + method, -_tmp,
                                                                               compressor_lengths + (current + NUM_COMPRESSORS));
     for (p = 0; p < compressors[current].methods; p ++) {
-      inverted_sequences[method + compressors[current].methods - 1 - p] = sequences[method + p];
-      inverted_lengths[method + compressors[current].methods - 1 - p] = lengths[method + p];
+      inverted_sequences[(int)method + (int)compressors[current].methods - 1 - (int)p] = sequences[method + p];
+      inverted_lengths[(int)method + (int)compressors[current].methods - 1 - (int)p] = lengths[method + p];
     }
     method += compressors[current].methods;
   }
--- a/tools/lz/uncomp.c
+++ b/tools/lz/uncomp.c
@@ -57,6 +57,7 @@
 
 unsigned char * get_uncompressed_data (const struct command * commands, const unsigned char * compressed, unsigned short * size) {
   const struct command * limit = commands + *size;
+  int _tmp;
   unsigned char * result = malloc(MAX_FILE_SIZE + MAX_COMMAND_COUNT);
   unsigned char * current = result;
   unsigned short p;
@@ -76,7 +77,8 @@
       default: {
         const unsigned char * ref = ((commands -> value < 0) ? current : result) + commands -> value;
         for (p = 0; p < commands -> count; p ++) {
-          current[p] = ref[(commands -> command == 6) ? -(int) p : p];
+          _tmp = p;
+          current[p] = ref[(commands -> command == 6) ? -_tmp : _tmp];
           if (commands -> command == 5) current[p] = bit_flipping_table[current[p]];
         }
         current += commands -> count;