Issue 396
[zxing.git] / cpp / core / src / zxing / oned / Code128Reader.cpp
index 943a574..6f638d5 100644 (file)
@@ -28,9 +28,9 @@
 namespace zxing {
        namespace oned {
                
-               const int CODE_PATTERNS_LENGHT = 107;
-               const int countersLenght = 6;
-               static const int CODE_PATTERNS[CODE_PATTERNS_LENGHT][countersLenght] = {
+               const int CODE_PATTERNS_LENGTH = 107;
+               const int countersLength = 6;
+               static const int CODE_PATTERNS[CODE_PATTERNS_LENGTH][countersLength] = {
                        {2, 1, 2, 2, 2, 2}, /* 0 */
                        {2, 2, 2, 1, 2, 2},
                        {2, 2, 2, 2, 2, 1},
@@ -155,7 +155,7 @@ namespace zxing {
                        }
                        
                        int counterPosition = 0;
-                       int counters[countersLenght] = {0,0,0,0,0,0};
+                       int counters[countersLength] = {0,0,0,0,0,0};
                        int patternStart = rowOffset;
                        bool isWhite = false;
                        int patternLength =  sizeof(counters) / sizeof(int);
@@ -206,13 +206,13 @@ namespace zxing {
                        recordPattern(row, rowOffset, counters, countersCount);
                        int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
                        int bestMatch = -1;
-                       for (int d = 0; d < CODE_PATTERNS_LENGHT; d++) {
-                               int pattern[countersLenght];
+                       for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) {
+                               int pattern[countersLength];
                                
-                               for(int ind = 0; ind< countersLenght; ind++){
+                               for(int ind = 0; ind< countersLength; ind++){
                                        pattern[ind] = CODE_PATTERNS[d][ind];
                                }
-//                             memcpy(pattern, CODE_PATTERNS[d], countersLenght);
+//                             memcpy(pattern, CODE_PATTERNS[d], countersLength);
                                int variance = patternMatchVariance(counters, countersCount, pattern, MAX_INDIVIDUAL_VARIANCE);
                                if (variance < bestVariance) {
                                        bestVariance = variance;
@@ -243,6 +243,7 @@ namespace zxing {
                                        codeSet = CODE_CODE_C;
                                        break;
                                default:
+                                       delete [] startPatternInfo;
                                        throw ReaderException("");
                        }
                        
@@ -254,7 +255,7 @@ namespace zxing {
                        
                        int lastStart = startPatternInfo[0];
                        int nextStart = startPatternInfo[1];
-                       int counters[countersLenght] = {0,0,0,0,0,0};
+                       int counters[countersLength] = {0,0,0,0,0,0};
                        
                        int lastCode = 0;
                        int code = 0;
@@ -271,7 +272,12 @@ namespace zxing {
                                lastCode = code;
                                
                                // Decode another code from image
+                               try {
                                code = decodeCode(row, counters, sizeof(counters)/sizeof(int), nextStart);
+                               } catch (ReaderException re) {
+                                       delete [] startPatternInfo;
+                                       throw re;
+                               }
                                
                                // Remember whether the last code was printable or not (excluding CODE_STOP)
                                if (code != CODE_STOP) {
@@ -286,8 +292,8 @@ namespace zxing {
                                
                                // Advance to where the next code will to start
                                lastStart = nextStart;
-                               int _countersLenght = sizeof(counters) / sizeof(int);
-                               for (int i = 0; i < _countersLenght; i++) {
+                               int _countersLength = sizeof(counters) / sizeof(int);
+                               for (int i = 0; i < _countersLength; i++) {
                                        nextStart += counters[i];
                                }
                                
@@ -296,6 +302,7 @@ namespace zxing {
                                        case CODE_START_A:
                                        case CODE_START_B:
                                        case CODE_START_C:
+                                               delete [] startPatternInfo;
                                                throw ReaderException("");
                                }
                                
@@ -418,6 +425,7 @@ namespace zxing {
                                nextStart++;
                        }
                        if (!row->isRange(nextStart, fminl(width, nextStart + (nextStart - lastStart) / 2), false)) {
+                               delete [] startPatternInfo;
                                throw ReaderException("");
                        }
                        
@@ -425,6 +433,7 @@ namespace zxing {
                        checksumTotal -= multiplier * lastCode;
                        // lastCode is the checksum then:
                        if (checksumTotal % 103 != lastCode) {
+                               delete [] startPatternInfo;
                                throw ReaderException("");
                        }
                        
@@ -444,6 +453,7 @@ namespace zxing {
 //                     String resultString(tmpResultString);
                        
                        if (tmpResultString.length() == 0) {
+                               delete [] startPatternInfo;
                                // Almost surely a false positive
                                throw ReaderException("");
                        }