Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(883)

Unified Diff: core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp

Issue 2357173005: Clean up fx_codec_fax.cpp. (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/fxcodec/codec/ccodec_faxmodule.h » ('j') | core/fxcodec/codec/fx_codec_fax.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 1b5bd024f8ddb3684d89d1a1c29804b2495ceaee..3d8e706642615a19d0dfefa844eb51ce3ac00e6c 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -7,6 +7,8 @@
#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
#include <limits.h>
+
+#include <algorithm>
#include <utility>
#include <vector>
@@ -174,20 +176,21 @@ uint32_t RunLengthDecode(const uint8_t* src_buf,
uint32_t old;
dest_size = 0;
while (i < src_size) {
+ if (src_buf[i] == 128)
+ break;
+
if (src_buf[i] < 128) {
old = dest_size;
dest_size += src_buf[i] + 1;
if (dest_size < old)
Tom Sepez 2016/09/23 21:55:48 note: OK, unsigned type.
return FX_INVALID_OFFSET;
i += src_buf[i] + 2;
Tom Sepez 2016/09/23 21:55:48 note: there's one value where this can overflow, e
Lei Zhang 2016/09/26 22:50:59 Sure.
- } else if (src_buf[i] > 128) {
+ } else {
old = dest_size;
dest_size += 257 - src_buf[i];
if (dest_size < old)
return FX_INVALID_OFFSET;
i += 2;
- } else {
- break;
}
}
if (dest_size >= _STREAM_MAX_SIZE_)
@@ -196,6 +199,9 @@ uint32_t RunLengthDecode(const uint8_t* src_buf,
i = 0;
int dest_count = 0;
while (i < src_size) {
+ if (src_buf[i] == 128)
+ break;
+
if (src_buf[i] < 128) {
uint32_t copy_len = src_buf[i] + 1;
uint32_t buf_left = src_size - i - 1;
@@ -207,7 +213,7 @@ uint32_t RunLengthDecode(const uint8_t* src_buf,
FXSYS_memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len);
dest_count += src_buf[i] + 1;
i += src_buf[i] + 2;
- } else if (src_buf[i] > 128) {
+ } else {
int fill = 0;
if (i < src_size - 1) {
fill = src_buf[i + 1];
@@ -215,15 +221,10 @@ uint32_t RunLengthDecode(const uint8_t* src_buf,
FXSYS_memset(dest_buf + dest_count, fill, 257 - src_buf[i]);
dest_count += 257 - src_buf[i];
i += 2;
- } else {
- break;
}
}
- uint32_t ret = i + 1;
- if (ret > src_size) {
- ret = src_size;
- }
- return ret;
+
+ return std::min(i + 1, src_size);
}
CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
@@ -233,16 +234,16 @@ CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(
int height,
const CPDF_Dictionary* pParams) {
int K = 0;
- FX_BOOL EndOfLine = FALSE;
- FX_BOOL ByteAlign = FALSE;
- FX_BOOL BlackIs1 = FALSE;
+ bool EndOfLine = false;
+ bool ByteAlign = false;
+ bool BlackIs1 = false;
int Columns = 1728;
int Rows = 0;
if (pParams) {
K = pParams->GetIntegerFor("K");
- EndOfLine = pParams->GetIntegerFor("EndOfLine");
- ByteAlign = pParams->GetIntegerFor("EncodedByteAlign");
- BlackIs1 = pParams->GetIntegerFor("BlackIs1");
+ EndOfLine = !!pParams->GetIntegerFor("EndOfLine");
Tom Sepez 2016/09/23 21:55:48 Yay, another not assigning 0 or 1 to FX_BOOL !!!
Lei Zhang 2016/09/26 22:50:59 Acknowledged.
+ ByteAlign = !!pParams->GetIntegerFor("EncodedByteAlign");
+ BlackIs1 = !!pParams->GetIntegerFor("BlackIs1");
Columns = pParams->GetIntegerFor("Columns", 1728);
Rows = pParams->GetIntegerFor("Rows");
if (Rows > USHRT_MAX) {
« no previous file with comments | « no previous file | core/fxcodec/codec/ccodec_faxmodule.h » ('j') | core/fxcodec/codec/fx_codec_fax.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698