From 6e01561b5ebcec1ee70e7de5e0d0da579afdd5f8 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Wed, 9 May 2018 23:10:36 -0700 Subject: [PATCH] Fix LZ11 compression. --- source/3ds/lz11.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/source/3ds/lz11.cpp b/source/3ds/lz11.cpp index efec022..b1e37a2 100644 --- a/source/3ds/lz11.cpp +++ b/source/3ds/lz11.cpp @@ -19,25 +19,27 @@ u32 lz11_get_occurence_length(u8* newPtr, u32 newLength, u8* oldPtr, u32 oldLeng } u32 maxLength = 0; - for(u32 i = 0; i < oldLength - 1; i++) { - u8* currentOldStart = oldPtr + i; - u32 currentLength = 0; - for(u32 j = 0; j < newLength; j++) { - if(*(currentOldStart + j) != *(newPtr + j)) { - break; + if(oldLength > 0) { + for(u32 i = 0; i < oldLength - 1; i++) { + u8* currentOldStart = oldPtr + i; + u32 currentLength = 0; + for(u32 j = 0; j < newLength; j++) { + if(*(currentOldStart + j) != *(newPtr + j)) { + break; + } + + currentLength++; } - currentLength++; - } + if(currentLength > maxLength) { + maxLength = currentLength; + if(disp != NULL) { + *disp = oldLength - i; + } - if(currentLength > maxLength) { - maxLength = currentLength; - if(disp != NULL) { - *disp = oldLength - i; - } - - if(maxLength == newLength) { - break; + if(maxLength == newLength) { + break; + } } } }