From a3228a81a80d6f57f6f4a693531038569ba623a9 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Thu, 25 Apr 2013 19:49:15 +0000 Subject: [PATCH] C++ for r2690 git-svn-id: https://zxing.googlecode.com/svn/trunk@2691 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/IllegalStateException.h | 35 +++++++++++++++++++ .../common/reedsolomon/ReedSolomonDecoder.cpp | 9 +++-- .../common/reedsolomon/ReedSolomonDecoder.h | 3 +- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 cpp/core/src/zxing/IllegalStateException.h diff --git a/cpp/core/src/zxing/IllegalStateException.h b/cpp/core/src/zxing/IllegalStateException.h new file mode 100644 index 000000000..dfaf5f387 --- /dev/null +++ b/cpp/core/src/zxing/IllegalStateException.h @@ -0,0 +1,35 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +#ifndef __ILLEGAL_STATE_EXCEPTION_H__ +#define __ILLEGAL_STATE_EXCEPTION_H__ + +/* + * Copyright 20011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may illegal use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +class IllegalStateException : public ReaderException { +public: + IllegalStateException() throw() {} + IllegalStateException(const char *msg) throw() : ReaderException(msg) {} + ~IllegalStateException() throw() {} +}; + +} + +#endif // __ILLEGAL_STATE_EXCEPTION_H__ diff --git a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp index ba802c268..c33407ec4 100644 --- a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp +++ b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp @@ -22,13 +22,14 @@ #include #include #include +#include -using namespace std; // remove - +using std::vector; using zxing::Ref; using zxing::ArrayRef; using zxing::ReedSolomonDecoder; using zxing::GenericGFPoly; +using zxing::IllegalStateException; // VC++ using zxing::GenericGF; @@ -107,6 +108,10 @@ vector > ReedSolomonDecoder::runEuclideanAlgorithm(Refmultiply(tLast)->addOrSubtract(tLastLast); + + if (r->getDegree() >= rLast->getDegree()) { + throw IllegalStateException("Division algorithm failed to reduce polynomial?"); + } } int sigmaTildeAtZero = t->getCoefficient(0); diff --git a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h index dc1037750..296a47964 100644 --- a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h +++ b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h @@ -38,8 +38,9 @@ public: ReedSolomonDecoder(Ref fld); ~ReedSolomonDecoder(); void decode(ArrayRef received, int twoS); -private: std::vector > runEuclideanAlgorithm(Ref a, Ref b, int R); + +private: ArrayRef findErrorLocations(Ref errorLocator); ArrayRef findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations); };