handle malloc(0) and calloc(0) uniformly on all platforms

also change lossless encoder logic, which was relying on explicit
NULL return from WebPSafeMalloc(0)

renamed function to CheckSizeArgumentsOverflow() explicitly

addresses issue #138

Change-Id: Ibbd51cc0281e60e86dfd4c5496274399e4c0f7f3
This commit is contained in:
skal
2013-01-22 10:34:35 +01:00
parent 8189feda50
commit 42f8f9346c
3 changed files with 16 additions and 7 deletions

View File

@ -221,7 +221,7 @@ static int GetHuffBitLengthsAndCodes(
}
// Create Huffman trees.
for (i = 0; i < histogram_image_size; ++i) {
for (i = 0; ok && (i < histogram_image_size); ++i) {
HuffmanTreeCode* const codes = &huffman_codes[5 * i];
VP8LHistogram* const histo = histogram_image->histograms[i];
ok = ok && VP8LCreateHuffmanTree(histo->literal_, 15, codes + 0);
@ -232,7 +232,11 @@ static int GetHuffBitLengthsAndCodes(
}
End:
if (!ok) free(mem_buf);
if (!ok) {
free(mem_buf);
// If one VP8LCreateHuffmanTree() above fails, we need to clean up behind.
memset(huffman_codes, 0, 5 * histogram_image_size * sizeof(*huffman_codes));
}
return ok;
}