mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-10-30 00:18:51 -04:00
Fix packbits for unsigned-char platforms
This commit is contained in:
committed by
Mirco Miranda
parent
83c1b0ceb1
commit
b94001fe46
@@ -66,28 +66,31 @@ inline qint64 packbitsDecompress(QIODevice *input, char *output, qint64 olen, bo
|
|||||||
{
|
{
|
||||||
qint64 j = 0;
|
qint64 j = 0;
|
||||||
for (qint64 rr = 0, available = olen; j < olen; available = olen - j) {
|
for (qint64 rr = 0, available = olen; j < olen; available = olen - j) {
|
||||||
char n;
|
char cn;
|
||||||
|
signed char n;
|
||||||
|
|
||||||
// check the output buffer space for the next run
|
// check the output buffer space for the next run
|
||||||
if (available < 129) {
|
if (available < 129) {
|
||||||
if (input->peek(&n, 1) != 1) { // end of data (or error)
|
if (input->peek(&cn, 1) != 1) { // end of data (or error)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (static_cast<signed char>(n) != -128 || allowN128)
|
n = static_cast<signed char>(cn);
|
||||||
if ((static_cast<signed char>(n) >= 0 ? qint64(n) + 1 : qint64(1 - n)) > available)
|
if (n != -128 || allowN128)
|
||||||
|
if ((n >= 0 ? qint64(n) + 1 : qint64(1 - n)) > available)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
if (input->read(&n, 1) != 1) { // end of data (or error)
|
if (input->read(&cn, 1) != 1) { // end of data (or error)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
n = static_cast<signed char>(cn);
|
||||||
|
|
||||||
if (static_cast<signed char>(n) == -128 && !allowN128) {
|
if (n == -128 && !allowN128) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static_cast<signed char>(n) >= 0) {
|
if (n >= 0) {
|
||||||
rr = input->read(output + j, qint64(n) + 1);
|
rr = input->read(output + j, qint64(n) + 1);
|
||||||
if (rr == -1) {
|
if (rr == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -98,7 +101,7 @@ inline qint64 packbitsDecompress(QIODevice *input, char *output, qint64 olen, bo
|
|||||||
if (input->read(&b, 1) != 1) {
|
if (input->read(&b, 1) != 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rr = qint64(1 - static_cast<signed char>(n));
|
rr = qint64(1 - n);
|
||||||
std::memset(output + j, b, size_t(rr));
|
std::memset(output + j, b, size_t(rr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user