diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2015-03-17 16:36:48 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:40:00 +0300 |
commit | 217de72ef7eba27f6d603e6ef0360aeaf7f59a1c (patch) | |
tree | 66a69a6b4b841a90a3d727929dca58384fbe2e67 /coding | |
parent | 3848db2389318c41b7c29a74cf9e5f2ba7e331dc (diff) |
fixed warnings for [coding]
Diffstat (limited to 'coding')
-rw-r--r-- | coding/arithmetic_codec.cpp | 14 | ||||
-rw-r--r-- | coding/bit_streams.cpp | 2 | ||||
-rw-r--r-- | coding/blob_indexer.cpp | 6 | ||||
-rw-r--r-- | coding/bzip2_compressor.cpp | 8 | ||||
-rw-r--r-- | coding/compressed_bit_vector.cpp | 13 | ||||
-rw-r--r-- | coding/compressed_varnum_vector.cpp | 3 | ||||
-rw-r--r-- | coding/reader_cache.hpp | 2 | ||||
-rw-r--r-- | coding/varint_vector.cpp | 8 | ||||
-rw-r--r-- | coding/zip_creator.cpp | 2 |
9 files changed, 33 insertions, 25 deletions
diff --git a/coding/arithmetic_codec.cpp b/coding/arithmetic_codec.cpp index d179540b9e..69f63f3331 100644 --- a/coding/arithmetic_codec.cpp +++ b/coding/arithmetic_codec.cpp @@ -6,6 +6,8 @@ #include "../base/assert.hpp" #include "../base/bits.hpp" +#include "../std/limits.hpp" + vector<uint32_t> FreqsToDistrTable(vector<uint32_t> const & origFreqs) { uint64_t freqLowerBound = 0; @@ -19,8 +21,10 @@ vector<uint32_t> FreqsToDistrTable(vector<uint32_t> const & origFreqs) for (uint32_t i = 0; i < origFreqs.size(); ++i) { uint32_t freq = origFreqs[i]; - if (freq > 0 && freq < minFreq) minFreq = freq; - if (freq > 0 && freq < freqLowerBound) freq = freqLowerBound; + if (freq > 0 && freq < minFreq) + minFreq = freq; + if (freq > 0 && freq < freqLowerBound) + freq = static_cast<uint32_t>(freqLowerBound); freqs.push_back(freq); sum += freq; result.push_back(sum); @@ -89,7 +93,8 @@ vector<uint8_t> ArithmeticEncoder::Finalize() void ArithmeticEncoder::PropagateCarry() { - int i = m_output.size() - 1; + ASSERT(m_output.size() > 0, ()); + int i = static_cast<int>(m_output.size() - 1); while (i >= 0 && m_output[i] == 0xFF) { m_output[i] = 0; @@ -112,7 +117,8 @@ ArithmeticDecoder::ArithmeticDecoder(Reader & reader, vector<uint32_t> const & d uint32_t ArithmeticDecoder::Decode() { - uint32_t l = 0, r = m_distrTable.size(), m = 0; + ASSERT(m_distrTable.size() <= numeric_limits<uint32_t>::max(), ()); + uint32_t l = 0, r = static_cast<uint32_t>(m_distrTable.size()), m = 0; uint32_t shiftedSize = m_size >> DISTR_SHIFT; while (r - l > 1) { diff --git a/coding/bit_streams.cpp b/coding/bit_streams.cpp index deb23a9342..31ea921b5a 100644 --- a/coding/bit_streams.cpp +++ b/coding/bit_streams.cpp @@ -59,7 +59,7 @@ uint64_t BitSource::Read(uint32_t readSize) // Second read, does an extra read using m_reader. if (readSize > 0) { - uint32_t read_byte_size = m_serialCur + sizeof(m_bits) <= m_serialEnd ? sizeof(m_bits) : m_serialEnd - m_serialCur; + size_t read_byte_size = m_serialCur + sizeof(m_bits) <= m_serialEnd ? sizeof(m_bits) : m_serialEnd - m_serialCur; m_reader.Read(m_serialCur, &m_bits, read_byte_size); m_serialCur += read_byte_size; m_bitsSize += read_byte_size * 8; diff --git a/coding/blob_indexer.cpp b/coding/blob_indexer.cpp index b86c10a5ae..9b2f71d792 100644 --- a/coding/blob_indexer.cpp +++ b/coding/blob_indexer.cpp @@ -38,8 +38,8 @@ uint64_t BlobIndexer::AddBlob(string const & blob) if (m_currentChunk.size() + blob.size() > m_maxUncompressedChunkSize) FlushChunk(); - m_blobChunkAndOffset.push_back( - (m_chunkOffset.size() << BITS_IN_CHUNK_SIZE) + m_currentChunk.size()); + m_blobChunkAndOffset.push_back(static_cast<uint32_t>( + (m_chunkOffset.size() << BITS_IN_CHUNK_SIZE) + m_currentChunk.size())); m_currentChunk.insert(m_currentChunk.end(), blob.begin(), blob.end()); @@ -55,7 +55,7 @@ void BlobIndexer::FlushChunk() m_writer.Write(compressedChunk.data(), compressedChunk.size()); WriteToSink(m_writer, static_cast<uint32_t>(m_currentChunk.size())); uint32_t const chunkPrevOffset = (m_chunkOffset.empty() ? 0 : m_chunkOffset.back()); - m_chunkOffset.push_back(compressedChunk.size() + 4 + chunkPrevOffset); + m_chunkOffset.push_back(static_cast<uint32_t>(compressedChunk.size() + 4 + chunkPrevOffset)); m_currentChunk.clear(); } } diff --git a/coding/bzip2_compressor.cpp b/coding/bzip2_compressor.cpp index 84916a39e0..ab08fab27b 100644 --- a/coding/bzip2_compressor.cpp +++ b/coding/bzip2_compressor.cpp @@ -11,8 +11,8 @@ size_t DecompressBZip2IntoFixedSize(char const * pSrc, size_t srcSize, char * pD { // TODO: Remove unnecessary copying. vector<char> src(pSrc, pSrc + srcSize); - unsigned int dstUsed = dstSize; - int error = BZ2_bzBuffToBuffDecompress(pDst, &dstUsed, &src[0], srcSize, 0, 0); + unsigned int dstUsed = static_cast<unsigned int>(dstSize); + int error = BZ2_bzBuffToBuffDecompress(pDst, &dstUsed, &src[0], static_cast<unsigned int>(srcSize), 0, 0); switch (error) { case BZ_OK: @@ -33,10 +33,10 @@ void CompressBZip2(int level, char const * pSrc, size_t srcSize, string & dst) { ASSERT(level >= 1 && level <= 9, (level)); dst.resize(srcSize + srcSize / 100 + 699); - unsigned int dstUsed = dst.size(); + unsigned int dstUsed = static_cast<unsigned int>(dst.size()); // TODO: Remove unnecessary copying. vector<char> src(pSrc, pSrc + srcSize); - int error = BZ2_bzBuffToBuffCompress(&dst[0], &dstUsed, &src[0], srcSize, level, 0, 0); + int error = BZ2_bzBuffToBuffCompress(&dst[0], &dstUsed, &src[0], static_cast<unsigned int>(srcSize), level, 0, 0); if (error == BZ_OK) dst.resize(dstUsed); else diff --git a/coding/compressed_bit_vector.cpp b/coding/compressed_bit_vector.cpp index feab4297b4..285a239f67 100644 --- a/coding/compressed_bit_vector.cpp +++ b/coding/compressed_bit_vector.cpp @@ -16,7 +16,7 @@ namespace { vector<uint32_t> SerialFreqsToDistrTable(Reader & reader, uint64_t & decodeOffset, uint64_t cnt) { vector<uint32_t> freqs; - for (uint64_t i = 0; i < cnt; ++i) freqs.push_back(VarintDecode(reader, decodeOffset)); + for (uint64_t i = 0; i < cnt; ++i) freqs.push_back(static_cast<uint32_t>(VarintDecode(reader, decodeOffset))); return FreqsToDistrTable(freqs); } } @@ -383,12 +383,12 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) { bool is_empty = (header & 4) != 0; if (!is_empty) { - posOnes.push_back(header >> 3); + posOnes.push_back(static_cast<uint32_t>(header >> 3)); prevOnePos = posOnes.back(); } while (decodeOffset < serialSize) { - posOnes.push_back(prevOnePos + VarintDecode(reader, decodeOffset) + 1); + posOnes.push_back(static_cast<uint32_t>(prevOnePos + VarintDecode(reader, decodeOffset) + 1)); prevOnePos = posOnes.back(); } } @@ -412,7 +412,7 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) { uint32_t bitsUsed = bitsUsedVec[i]; uint64_t diff = 0; if (bitsUsed > 0) diff = ((uint64_t(1) << (bitsUsed - 1)) | bitReader.Read(bitsUsed - 1)) + 1; else diff = 1; - posOnes.push_back(prevOnePos + diff); + posOnes.push_back(static_cast<uint32_t>(prevOnePos + diff)); prevOnePos += diff; } decodeOffset = serialSize; @@ -431,7 +431,8 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) { if (!isFirstOne) zerosRangeSize = VarintDecode(reader, decodeOffset) + 1; else isFirstOne = false; uint64_t onesRangeSize = VarintDecode(reader, decodeOffset) + 1; sum += zerosRangeSize; - for (uint64_t i = sum; i < sum + onesRangeSize; ++i) posOnes.push_back(i); + for (uint64_t i = sum; i < sum + onesRangeSize; ++i) + posOnes.push_back(static_cast<uint32_t>(i)); sum += onesRangeSize; } } @@ -475,7 +476,7 @@ vector<uint32_t> DecodeCompressedBitVector(Reader & reader) { if (bitsUsed > 0) onesRangeSize = ((uint64_t(1) << (bitsUsed - 1)) | bitReader.Read(bitsUsed - 1)) + 1; else onesRangeSize = 1; ++i1; sum += zerosRangeSize; - for (uint64_t j = sum; j < sum + onesRangeSize; ++j) posOnes.push_back(j); + for (uint64_t j = sum; j < sum + onesRangeSize; ++j) posOnes.push_back(static_cast<uint32_t>(j)); sum += onesRangeSize; } CHECK(i0 == cntElements0 && i1 == cntElements1, ()); diff --git a/coding/compressed_varnum_vector.cpp b/coding/compressed_varnum_vector.cpp index ff5be09073..538458d3f5 100644 --- a/coding/compressed_varnum_vector.cpp +++ b/coding/compressed_varnum_vector.cpp @@ -105,7 +105,8 @@ CompressedVarnumVectorReader::CompressedVarnumVectorReader(Reader & reader) m_supportSums = VarintDecode(m_reader, offset) != 0; vector<uint32_t> sizesFreqs; uint64_t freqsCnt = VarintDecode(m_reader, offset); - for (uint32_t i = 0; i < freqsCnt; ++i) sizesFreqs.push_back(VarintDecode(m_reader, offset)); + for (uint32_t i = 0; i < freqsCnt; ++i) + sizesFreqs.push_back(static_cast<uint32_t>(VarintDecode(m_reader, offset))); m_distrTable = FreqsToDistrTable(sizesFreqs); m_numsEncodedOffset = offset; diff --git a/coding/reader_cache.hpp b/coding/reader_cache.hpp index 6abc96095b..793f5207fd 100644 --- a/coding/reader_cache.hpp +++ b/coding/reader_cache.hpp @@ -55,7 +55,7 @@ public: if (size == 0) return; ASSERT_LESS_OR_EQUAL(pos + size, reader.Size(), (pos, size, reader.Size())); - m_Stats.m_ReadSize(size); + m_Stats.m_ReadSize(static_cast<uint32_t>(size)); char * pDst = static_cast<char *>(p); uint64_t pageNum = pos >> m_LogPageSize; size_t const firstPageOffset = static_cast<size_t>(pos - (pageNum << m_LogPageSize)); diff --git a/coding/varint_vector.cpp b/coding/varint_vector.cpp index b874e10cf2..f92653bd66 100644 --- a/coding/varint_vector.cpp +++ b/coding/varint_vector.cpp @@ -56,7 +56,7 @@ void VectorBuilder::AddNum(uint64_t num) if (m_numsCount % m_numElemPerTableEntry == 0) { TableEntry tableEntry; - tableEntry.pos = m_serialNums.size(); + tableEntry.pos = static_cast<uint32_t>(m_serialNums.size()); tableEntry.sum = m_sum; m_selectTable.push_back(tableEntry); } @@ -143,7 +143,7 @@ void Vector::FindByIndex(uint64_t index, uint32_t & serialPos, uint64_t & sumBef uint64_t num = VarintDecode(m_reader, numOffset); sum += num; } - serialPos = numOffset - m_serialNumsOffset; + serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset); sumBefore = sum; } @@ -191,7 +191,7 @@ void Vector::FindBySum(uint64_t sum, uint32_t & serialPos, uint64_t & sumBefore, ++countBefore; } - serialPos = numOffset - m_serialNumsOffset; + serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset); sumBefore = numsSum; } @@ -201,7 +201,7 @@ void Vector::Read(uint32_t & serialPos, uint64_t & num) uint64_t numOffset = m_serialNumsOffset + serialPos; num = VarintDecode(m_reader, numOffset); - serialPos = numOffset - m_serialNumsOffset; + serialPos = static_cast<uint32_t>(numOffset - m_serialNumsOffset); } } diff --git a/coding/zip_creator.cpp b/coding/zip_creator.cpp index 3fc72f932d..2a850d1f55 100644 --- a/coding/zip_creator.cpp +++ b/coding/zip_creator.cpp @@ -92,7 +92,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str size_t const toRead = min(ZIP_FILE_BUFFER_SIZE, fileSize - currSize); file.Read(currSize, &buffer[0], toRead); - if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), &buffer[0], toRead)) + if (ZIP_OK != zipWriteInFileInZip(zip.Handle(), &buffer[0], static_cast<uint32_t>(toRead))) return false; currSize += toRead; |