From 57cb5447d68c01eddba0618c3a8fe450b180f917 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 1 Sep 2017 11:14:18 -0400 Subject: Adjust loops in preperation for FX_STRSIZE int->size_t Adjust loop conditions and behaviours in preperation for convering the underlying type of FX_STRSIZE to size_t. These changes are not dependent on the type switch occuring, so can be landed before hand. BUG=pdfium:828 Change-Id: I5f950c99c10e5ef0836959e3b1dd2e09f8f5afc0 Reviewed-on: https://pdfium-review.googlesource.com/12750 Commit-Queue: Ryan Harrison Reviewed-by: Henrique Nakashima --- fxbarcode/oned/BC_OnedEAN8Writer.cpp | 16 +++++++--------- fxbarcode/oned/BC_OnedUPCAWriter.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'fxbarcode/oned') diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp index 5ca53e0568..6810e9e285 100644 --- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp @@ -83,20 +83,18 @@ CFX_WideString CBC_OnedEAN8Writer::FilterContents( } int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString& contents) { - FX_STRSIZE odd = 0; - FX_STRSIZE even = 0; - FX_STRSIZE j = 1; - for (FX_STRSIZE i = contents.GetLength() - 1; i >= 0; i--) { - if (j % 2) { - odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); + int32_t odd = 0; + int32_t even = 0; + for (FX_STRSIZE i = contents.GetLength(); i > 0; i--) { + if (i % 2) { + odd += FXSYS_atoi(contents.Mid(i - 1, 1).c_str()); } else { - even += FXSYS_atoi(contents.Mid(i, 1).c_str()); + even += FXSYS_atoi(contents.Mid(i - 1, 1).c_str()); } - j++; } int32_t checksum = (odd * 3 + even) % 10; checksum = (10 - checksum) % 10; - return (checksum); + return checksum; } uint8_t* CBC_OnedEAN8Writer::EncodeWithHint(const CFX_ByteString& contents, diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp index 87b68d364f..5782fe4e1a 100644 --- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp +++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp @@ -70,17 +70,17 @@ int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { int32_t odd = 0; int32_t even = 0; FX_STRSIZE j = 1; - for (FX_STRSIZE i = contents.GetLength() - 1; i >= 0; i--) { + for (FX_STRSIZE i = contents.GetLength(); i > 0; i--) { if (j % 2) { - odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); + odd += FXSYS_atoi(contents.Mid(i - 1, 1).c_str()); } else { - even += FXSYS_atoi(contents.Mid(i, 1).c_str()); + even += FXSYS_atoi(contents.Mid(i - 1, 1).c_str()); } j++; } int32_t checksum = (odd * 3 + even) % 10; checksum = (10 - checksum) % 10; - return (checksum); + return checksum; } uint8_t* CBC_OnedUPCAWriter::EncodeWithHint(const CFX_ByteString& contents, -- cgit v1.2.3