diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2015-05-28 13:49:23 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2015-05-28 13:49:23 +0200 |
commit | 1b38ceb0d4bb4ae32cb93c295e3ef493b91f9a78 (patch) | |
tree | 5634e1d3fd17386975db1c0d4e95176db098bc1f /src/huffman | |
parent | c26e12c79f2a5e0c092de4a62565bdae4bf5a7dd (diff) |
+ Fixed defects found by Coverity (well, most of them)
Diffstat (limited to 'src/huffman')
-rw-r--r-- | src/huffman/huff.cpp | 8 | ||||
-rw-r--r-- | src/huffman/huff.h | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/huffman/huff.cpp b/src/huffman/huff.cpp index c973580..1636a80 100644 --- a/src/huffman/huff.cpp +++ b/src/huffman/huff.cpp @@ -409,7 +409,10 @@ THuffmannTree::THuffmannTree(bool bCompression) pFirst = pLast = LIST_HEAD(); MinValidValue = 1; ItemsUsed = 0; - + bIsCmp0 = 0; + + memset(ItemsByByte, 0, sizeof(ItemsByByte)); + // If we are going to decompress data, we need to invalidate all item links // We do so by zeroing their ValidValue, so it becomes lower MinValidValue if(bCompression == false) @@ -737,7 +740,8 @@ unsigned int THuffmannTree::DecodeOneByte(TInputStream * is) else { // Limit the quick-decompress item to lower amount of bits - ItemLinkIndex &= (0xFFFFFFFF >> (32 - BitCount)); + // Coverity fix 84457: (x >> 32) has undefined behavior + ItemLinkIndex = (BitCount != 0) ? ItemLinkIndex & (0xFFFFFFFF >> (32 - BitCount)) : 0; while(ItemLinkIndex < LINK_ITEM_COUNT) { // Fill the quick-decompress item diff --git a/src/huffman/huff.h b/src/huffman/huff.h index b0a54ee..2bd5abc 100644 --- a/src/huffman/huff.h +++ b/src/huffman/huff.h @@ -67,7 +67,7 @@ enum TInsertPoint // Huffmann tree item struct THTreeItem { - THTreeItem() { pPrev = pNext = NULL;} + THTreeItem() { pPrev = pNext = NULL; DecompressedValue = 0; Weight = 0; pParent = pChildLo = NULL; } // ~THTreeItem() { RemoveItem(); } void RemoveItem(); |