diff --git a/backend/aztec.c b/backend/aztec.c index b7cfa83b..bb9d1ca5 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -102,7 +102,7 @@ int aztec_text_process(unsigned char source[], char binary_string[]) } i++; - }while(i < maplength); + }while(i < (maplength - 1)); /* look for blocks of characters which use the same table */ blocks = 0; @@ -136,7 +136,7 @@ int aztec_text_process(unsigned char source[], char binary_string[]) if(blockmap[0][blocks - 1] & 8) { blockmap[0][blocks - 1] = 8; } /* look for adjacent blocks which can use the same table (right to left search) */ - for(i = blocks; i > 0; i--) { + for(i = blocks - 1; i > 0; i--) { if(blockmap[0][i] & blockmap[0][i + 1]) { blockmap[0][i] = (blockmap[0][i] & blockmap[0][i + 1]); } @@ -657,7 +657,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) for(i = 0; i <= data_length; i++) { adjusted_string[i] = binary_string[i]; } - + /* Data string can't have all '0's or all '1's in a block */ i = 0; do{ @@ -675,7 +675,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) insert(adjusted_string, i+(codeword_size - 1), '0'); } i += codeword_size; - } while (i < strlen(adjusted_string)); + } while ((i + codeword_size) < strlen(adjusted_string)); adjusted_length = strlen(adjusted_string); } while(adjusted_length > data_maxsize); @@ -725,7 +725,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) insert(adjusted_string, i+(codeword_size - 1), '0'); } i += codeword_size; - } while (i < strlen(adjusted_string)); + } while ((i + codeword_size) < strlen(adjusted_string)); adjusted_length = strlen(adjusted_string); /* Check if the data actually fits into the selected symbol size */ diff --git a/backend/composite.c b/backend/composite.c index 809140f3..0034c3a6 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -131,10 +131,10 @@ int cc_a(struct zint_symbol *symbol, unsigned char source[], int cc_width) bitlen = ustrlen(source); - for(i = bitlen; i < 197; i++) { + for(i = bitlen; i < 208; i++) { source[i] = '0'; } - source[197] = '\0'; + source[208] = '\0'; for(segment = 0; segment < 13; segment++) { strpos = segment * 16; diff --git a/backend/reedsol.c b/backend/reedsol.c index a0a84dc5..81515ad4 100644 --- a/backend/reedsol.c +++ b/backend/reedsol.c @@ -62,13 +62,6 @@ void rs_init_gf(int poly) { int m, b, p, v; - // Return storage from previous setup - if (log) { - free(log); - free(alog); - free(rspoly); - rspoly = NULL; - } // Find the top bit, and hence the symbol size for (b = 1, m = 0; b <= poly; b <<= 1) m++; @@ -102,8 +95,6 @@ void rs_init_code(int nsym, int index) { int i, k; - if (rspoly) - free(rspoly); rspoly = (int *)malloc(sizeof(int) * (nsym + 1)); rlen = nsym; @@ -143,6 +134,12 @@ void rs_encode(int len, unsigned char *data, unsigned char *res) else res[0] = 0; } + + free(log); + free(alog); + free(rspoly); + rspoly = NULL; + } void rs_encode_long(int len, unsigned int *data, unsigned int *res) @@ -166,5 +163,10 @@ void rs_encode_long(int len, unsigned int *data, unsigned int *res) else res[0] = 0; } + + free(log); + free(alog); + free(rspoly); + rspoly = NULL; } diff --git a/backend/rss.c b/backend/rss.c index c560dd4a..8f03e76d 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -933,7 +933,7 @@ int general_rules(char field[], char type[]) current = block[1][i]; next = block[1][i + 1]; - if(current == ISOIEC) { + if((current == ISOIEC) && (i != (block_count - 1))) { if((next == ANY_ENC) && (block[0][i + 1] >= 4)) { block[1][i + 1] = NUMERIC; } @@ -952,7 +952,7 @@ int general_rules(char field[], char type[]) block[1][i] = ALPHA; } - if(current == ALPHA) { + if((current == ALPHA) && (i != (block_count - 1))) { if((next == ANY_ENC) && (block[0][i + 1] >= 6)) { block[1][i + 1] = NUMERIC; } @@ -1798,8 +1798,12 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b } /* Now add padding to binary string */ - if (general_field_type[strlen(general_field) - 1] == NUMERIC) { - strcpy(padstring, "000000100001"); + if(strlen(general_field) != 0) { + if (general_field_type[strlen(general_field) - 1] == NUMERIC) { + strcpy(padstring, "000000100001"); + } else { + strcpy(padstring, "001000010000"); + } } else { strcpy(padstring, "001000010000"); }