diff options
author | Wei Li <weili@chromium.org> | 2016-03-21 11:20:44 -0700 |
---|---|---|
committer | Wei Li <weili@chromium.org> | 2016-03-21 11:20:44 -0700 |
commit | d4e8f1222ca17b57ac74019b2fc3706e1192645c (patch) | |
tree | 0dd5e1627fd684205631f875cbf5946178177766 /core/fxcodec/codec | |
parent | 34fa8d90ae2f60fae219e4dbeff14c053d2e8eef (diff) | |
download | pdfium-d4e8f1222ca17b57ac74019b2fc3706e1192645c.tar.xz |
Re-enable several MSVC warnings
Re-enable the following warnings:
4245: signed/unsigned conversion mismatch;
4310: cast may truncate data;
4389: operator on signed/unsigned mismatch;
4701: use potentially uninitialized local variable;
4706: assignment within conditional expression
Clean up the code to avoid those warnings.
BUG=pdfium:29
R=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1801383002 .
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r-- | core/fxcodec/codec/codec_int.h | 1 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_flate.cpp | 6 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_jpx_opj.cpp | 16 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec_tiff.cpp | 6 |
4 files changed, 16 insertions, 13 deletions
diff --git a/core/fxcodec/codec/codec_int.h b/core/fxcodec/codec/codec_int.h index d2f44dd674..d19a694222 100644 --- a/core/fxcodec/codec/codec_int.h +++ b/core/fxcodec/codec/codec_int.h @@ -47,7 +47,6 @@ class CCodec_ScanlineDecoder : public ICodec_ScanlineDecoder { ~CCodec_ScanlineDecoder() override; // ICodec_ScanlineDecoder - FX_DWORD GetSrcOffset() override { return -1; } void DownScale(int dest_width, int dest_height) override; const uint8_t* GetScanline(int line) override; FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) override; diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 49a4f34166..27416f1c67 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -147,7 +147,7 @@ int CLZWDecoder::Decode(uint8_t* dest_buf, m_Early = bEarlyChange ? 1 : 0; m_nCodes = 0; FX_DWORD old_code = (FX_DWORD)-1; - uint8_t last_char; + uint8_t last_char = 0; while (1) { if (m_InPos + m_CodeLen > src_size * 8) { break; @@ -942,7 +942,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, offset = src_size; int err = decoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChange); if (err || dest_size == 0 || dest_size + 1 < dest_size) { - return -1; + return static_cast<FX_DWORD>(-1); } } { @@ -965,7 +965,7 @@ FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); } - return ret ? offset : -1; + return ret ? offset : static_cast<FX_DWORD>(-1); } FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp index aaa89388b8..a57b93df22 100644 --- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -24,16 +24,17 @@ static void fx_warning_callback(const char* msg, void* client_data) { static void fx_info_callback(const char* msg, void* client_data) { (void)client_data; } + OPJ_SIZE_T opj_read_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } // Reads at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T readlength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -41,16 +42,17 @@ OPJ_SIZE_T opj_read_from_memory(void* p_buffer, srcData->offset += readlength; return readlength; } + OPJ_SIZE_T opj_write_from_memory(void* p_buffer, OPJ_SIZE_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } // Writes at EOF return an error code. if (srcData->offset >= srcData->src_size) { - return -1; + return static_cast<OPJ_SIZE_T>(-1); } OPJ_SIZE_T bufferLength = srcData->src_size - srcData->offset; OPJ_SIZE_T writeLength = nb_bytes < bufferLength ? nb_bytes : bufferLength; @@ -58,17 +60,18 @@ OPJ_SIZE_T opj_write_from_memory(void* p_buffer, srcData->offset += writeLength; return writeLength; } + OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { - return -1; + return static_cast<OPJ_OFF_T>(-1); } // Offsets are signed and may indicate a negative skip. Do not support this // because of the strange return convention where either bytes skipped or // -1 is returned. Following that convention, a successful relative seek of // -1 bytes would be required to to give the same result as the error case. if (nb_bytes < 0) { - return -1; + return static_cast<OPJ_OFF_T>(-1); } // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd. uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes); @@ -89,6 +92,7 @@ OPJ_OFF_T opj_skip_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { } return nb_bytes; } + OPJ_BOOL opj_seek_from_memory(OPJ_OFF_T nb_bytes, void* p_user_data) { DecodeData* srcData = static_cast<DecodeData*>(p_user_data); if (!srcData || !srcData->src_data || srcData->src_size == 0) { diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp index 2af92f2f12..0312622fb4 100644 --- a/core/fxcodec/codec/fx_codec_tiff.cpp +++ b/core/fxcodec/codec/fx_codec_tiff.cpp @@ -122,20 +122,20 @@ static toff_t _tiff_seek(thandle_t context, toff_t offset, int whence) { case 2: if (pTiffContext->isDecoder) { if (pTiffContext->io.in->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast<toff_t>(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.in->GetSize() - offset); } else { if (pTiffContext->io.out->GetSize() < (FX_FILESIZE)offset) { - return -1; + return static_cast<toff_t>(-1); } pTiffContext->offset = (FX_DWORD)(pTiffContext->io.out->GetSize() - offset); } break; default: - return -1; + return static_cast<toff_t>(-1); } ASSERT(pTiffContext->isDecoder ? (pTiffContext->offset <= (FX_DWORD)pTiffContext->io.in->GetSize()) |