gifflen-sample
gifflen-sample copied to clipboard
signal 7 (SIGBUS), code 2 (BUS_ADRERR) on large images
When encoding large images (640x480) + I encounter a crash during quantization especially on this line (gifflen.cpp:919):
while (i < samplepixels) {
/*b = p[0] << netbiasshift;
g = p[1] << netbiasshift;
r = p[2] << netbiasshift;*/
b = (((*p)) & 0xff) << netbiasshift;
g = (((*p) >> 8) & 0xff) << netbiasshift;
r = (((*p) >> 16) & 0xff) << netbiasshift;
j = contest(b,g,r);
*p might not be pointing to the right place
Happens both on x86 and ARM, so it wouldn't be alignment issues.
Just located the source of the weirdness!
on line 928:
if (p >= (unsigned int *)lim) p -= lengthcount;
p is deducted by lengthcount, however lengthcount is w_h_4 due to:
435: initnet(srcimage->bits, srcimage->width*srcimage->height*PIXEL_SIZE, 31-quality);
however p is unsigned *int already, and thus p-=lengthcount results in an additioal *4 in pointer decrement. What I did was:
if (p >= (unsigned int *)lim) p = (unsigned int*) ((char*)p - lengthcount);
and it was solved. Maybe if you have a better way of resolving it?
@jedld thx, using your solution, no crash anymore