From ed48c1a42b2f9a0c8cb04185c180c6424bad3b83 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 25 Aug 2017 15:34:41 -0400 Subject: Add help IsValid* methods to string classes The various string classes, CFX_ByteString, CFX_ByteStringC, CFX_WideString, and CFX_WideStringC, have many conditionals that are effectively determining if a value is a valid index or length. This CL refactors the logic into one place per class, so it only needs to be changed once if its behaviour needs to change. It also make the some of the methods stricter on the inputs they will accept. BUG=pdfium:828 Change-Id: Iadcdaa34a6d862a2804485770027179c89dc6956 Reviewed-on: https://pdfium-review.googlesource.com/12030 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- fxbarcode/oned/BC_OnedCode128Writer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'fxbarcode/oned') diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp index 95a95b69e2..a6dc749a76 100644 --- a/fxbarcode/oned/BC_OnedCode128Writer.cpp +++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp @@ -193,7 +193,9 @@ int32_t CBC_OnedCode128Writer::Encode128C(const CFX_ByteString& contents, int32_t patternIndex; char ch = contents[position]; if (std::isdigit(ch)) { - patternIndex = FXSYS_atoi(contents.Mid(position, 2).c_str()); + patternIndex = FXSYS_atoi( + contents.Mid(position, position + 1 < contents.GetLength() ? 2 : 1) + .c_str()); ++position; if (position < contents.GetLength() && std::isdigit(contents[position])) ++position; -- cgit v1.2.3