summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-04-12 09:26:37 +0200
committerKim Woelders <kim@woelders.dk>2021-04-16 17:15:06 +0200
commit4fa2ad8566b3203f857224d4106d4aa0acd2d9ff (patch)
treee123d45f25a27d5304e2020e76b4d015537363c7
parent90c5f5a26a8551699c2847dfcaee4dab552f7aca (diff)
LBM loader: Fix handling of missing RLE data
The missing bytes were cleared at the start of the line, not the end.
-rw-r--r--src/modules/loaders/loader_lbm.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/modules/loaders/loader_lbm.c b/src/modules/loaders/loader_lbm.c
index 434f723..155f9da 100644
--- a/src/modules/loaders/loader_lbm.c
+++ b/src/modules/loaders/loader_lbm.c
@@ -189,15 +189,18 @@ bodyrow(unsigned char *p, int z, ILBM * ilbm)
189 return; 189 return;
190 } 190 }
191 191
192 for (i = 0; i < z;) 192 for (i = 0; i < z; i += w)
193 { 193 {
194 b = ilbm->body.data[ilbm->offset++]; 194 b = ilbm->body.data[ilbm->offset++];
195 while (b == 0x80 && ilbm->offset < ilbm->body.size) 195 while (b == 0x80 && ilbm->offset < ilbm->body.size)
196 b = ilbm->body.data[ilbm->offset++]; 196 b = ilbm->body.data[ilbm->offset++];
197 if (ilbm->offset >= ilbm->body.size)
198 break;
199 197
200 if (b & 0x80) 198 if (ilbm->offset >= ilbm->body.size)
199 {
200 w = z - i;
201 memset(p + i, 0, w);
202 }
203 else if (b & 0x80)
201 { 204 {
202 w = (0x100 - b) + 1; 205 w = (0x100 - b) + 1;
203 if (w > z - i) 206 if (w > z - i)
@@ -205,7 +208,6 @@ bodyrow(unsigned char *p, int z, ILBM * ilbm)
205 208
206 b = ilbm->body.data[ilbm->offset++]; 209 b = ilbm->body.data[ilbm->offset++];
207 memset(p + i, b, w); 210 memset(p + i, b, w);
208 i += w;
209 } 211 }
210 else 212 else
211 { 213 {
@@ -214,13 +216,10 @@ bodyrow(unsigned char *p, int z, ILBM * ilbm)
214 w = ilbm->body.size - ilbm->offset; 216 w = ilbm->body.size - ilbm->offset;
215 x = (w <= z - i) ? w : z - i; 217 x = (w <= z - i) ? w : z - i;
216 memcpy(p + i, ilbm->body.data + ilbm->offset, x); 218 memcpy(p + i, ilbm->body.data + ilbm->offset, x);
217 i += x;
218 ilbm->offset += w; 219 ilbm->offset += w;
220 w = x;
219 } 221 }
220 } 222 }
221
222 if (i < z)
223 memset(p, 0, z - i);
224} 223}
225 224
226/*------------------------------------------------------------------------------ 225/*------------------------------------------------------------------------------