Fix incorrect padding construction spotted by Xcode Analyzer

This commit is contained in:
Nikolaj Schlej 2020-11-22 20:56:51 -08:00
parent 115d338a70
commit 5645599c58
3 changed files with 20 additions and 19 deletions

View File

@ -4655,29 +4655,30 @@ make_partition_table_consistent:
}
}
else if (partitions[i].type == Types::Padding) {
UByteArray partition = region.mid(partitions[i].ptEntry.Offset, partitions[i].ptEntry.Size);
UByteArray padding = region.mid(partitions[i].ptEntry.Offset, partitions[i].ptEntry.Size);
// Get info
name = UString("Padding");
info = usprintf("Full size: %Xh (%u)",
partition.size(), partition.size());
padding.size(), padding.size());
// Add tree item
model->addItem(localOffset + partitions[i].ptEntry.Offset, Types::Padding, getPaddingType(partition), name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, parent);
model->addItem(localOffset + partitions[i].ptEntry.Offset, Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), Fixed, parent);
}
}
// Add padding after the last region
if ((UINT64)partitions.back().ptEntry.Offset + (UINT64)partitions.back().ptEntry.Size < regionSize) {
UByteArray partition = region.mid(partitions.back().ptEntry.Offset + partitions.back().ptEntry.Size, regionSize - padding.ptEntry.Offset);
UINT64 usedSize = (UINT64)partitions.back().ptEntry.Offset + (UINT64)partitions.back().ptEntry.Size;
UByteArray padding = region.mid(partitions.back().ptEntry.Offset + partitions.back().ptEntry.Size, (int)(regionSize - usedSize));
// Get info
name = UString("Padding");
info = usprintf("Full size: %Xh (%u)",
partition.size(), partition.size());
padding.size(), padding.size());
// Add tree item
model->addItem(localOffset + partitions.back().ptEntry.Offset + partitions.back().ptEntry.Size, Types::Padding, getPaddingType(partition), name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, parent);
model->addItem(localOffset + partitions.back().ptEntry.Offset + partitions.back().ptEntry.Size, Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), Fixed, parent);
}
return U_SUCCESS;

View File

@ -1341,7 +1341,7 @@ local uInt longest_match(s, cur_match)
* are always equal when the other bytes match, given that
* the hash keys are equal and that HASH_BITS >= 8.
*/
scan += 2, match++;
scan += 2; match++;
Assert(*scan == *match, "match[2]?");
/* We check for insufficient lookahead only every 8th comparison;
@ -1958,7 +1958,7 @@ local block_state deflate_slow(s, flush)
/* Find the longest match, discarding those <= prev_length.
*/
s->prev_length = s->match_length, s->prev_match = s->match_start;
s->prev_length = s->match_length; s->prev_match = s->match_start;
s->match_length = MIN_MATCH-1;
if (hash_head != NIL && s->prev_length < s->max_lazy_match &&

View File

@ -510,7 +510,7 @@ local void gen_bitlen(s, desc)
for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++;
if (bits > max_length) {bits = max_length; overflow++;}
tree[n].Len = (ush)bits;
/* We overwrite tree[n].Dad which is no longer needed */
@ -627,7 +627,7 @@ local void build_tree(s, desc)
* heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
* heap[0] is not used.
*/
s->heap_len = 0, s->heap_max = HEAP_SIZE;
s->heap_len = 0; s->heap_max = HEAP_SIZE;
for (n = 0; n < elems; n++) {
if (tree[n].Freq != 0) {
@ -713,7 +713,7 @@ local void scan_tree (s, tree, max_code)
int max_count = 7; /* max repeat count */
int min_count = 4; /* min repeat count */
if (nextlen == 0) max_count = 138, min_count = 3;
if (nextlen == 0) {max_count = 138; min_count = 3;}
tree[max_code+1].Len = (ush)0xffff; /* guard */
for (n = 0; n <= max_code; n++) {
@ -732,11 +732,11 @@ local void scan_tree (s, tree, max_code)
}
count = 0; prevlen = curlen;
if (nextlen == 0) {
max_count = 138, min_count = 3;
max_count = 138; min_count = 3;
} else if (curlen == nextlen) {
max_count = 6, min_count = 3;
max_count = 6; min_count = 3;
} else {
max_count = 7, min_count = 4;
max_count = 7; min_count = 4;
}
}
}
@ -759,7 +759,7 @@ local void send_tree (s, tree, max_code)
int min_count = 4; /* min repeat count */
/* tree[max_code+1].Len = -1; */ /* guard already set */
if (nextlen == 0) max_count = 138, min_count = 3;
if (nextlen == 0) {max_count = 138; min_count = 3;}
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
@ -783,11 +783,11 @@ local void send_tree (s, tree, max_code)
}
count = 0; prevlen = curlen;
if (nextlen == 0) {
max_count = 138, min_count = 3;
max_count = 138; min_count = 3;
} else if (curlen == nextlen) {
max_count = 6, min_count = 3;
max_count = 6; min_count = 3;
} else {
max_count = 7, min_count = 4;
max_count = 7; min_count = 4;
}
}
}
@ -1162,7 +1162,7 @@ local unsigned bi_reverse(code, len)
register unsigned res = 0;
do {
res |= code & 1;
code >>= 1, res <<= 1;
code >>= 1; res <<= 1;
} while (--len > 0);
return res >> 1;
}