summaryrefslogtreecommitdiff
path: root/fxbarcode/oned/BC_OnedEAN13Writer.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-09-01 16:01:44 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-01 20:29:34 +0000
commitab3c111433229fc79275c4b413b24bec6f5463ce (patch)
treeceee33196d76ebded37cd5c9e7ebfd35303215c2 /fxbarcode/oned/BC_OnedEAN13Writer.cpp
parenta2188df09255b49ad41a89ae9b5de640d0b03126 (diff)
downloadpdfium-ab3c111433229fc79275c4b413b24bec6f5463ce.tar.xz
Fix EAN-13 checksum and add unit tests.
Parity in EAN-13 is considered counting digits from right to left, starting at 1. Bug: pdfium:882 Change-Id: I3e586499091b8400daf93657eb9878f29d9e6922 Reviewed-on: https://pdfium-review.googlesource.com/12910 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fxbarcode/oned/BC_OnedEAN13Writer.cpp')
-rw-r--r--fxbarcode/oned/BC_OnedEAN13Writer.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index dddb9cc24d..e7642de56d 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -79,17 +79,16 @@ CFX_WideString CBC_OnedEAN13Writer::FilterContents(
int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) {
int32_t odd = 0;
int32_t even = 0;
- FX_STRSIZE j = 1;
- for (FX_STRSIZE i = 0; i < contents.GetLength(); i++) {
- if (j % 2) {
- odd += FXSYS_DecimalCharToInt(contents[i]);
+ FX_STRSIZE parity = 1;
+ for (FX_STRSIZE i = contents.GetLength(); i > 0; i--) {
+ if (parity % 2) {
+ odd += FXSYS_DecimalCharToInt(contents[i - 1]);
} else {
- even += FXSYS_DecimalCharToInt(contents[i]);
+ even += FXSYS_DecimalCharToInt(contents[i - 1]);
}
- j++;
+ parity++;
}
- int32_t checksum = 10 - (odd * 3 + even) % 10;
- return checksum;
+ return (10 - (odd * 3 + even) % 10) % 10;
}
uint8_t* CBC_OnedEAN13Writer::EncodeWithHint(const CFX_ByteString& contents,