diff --git a/backend/code.c b/backend/code.c index 2aa63709..63fccc5e 100644 --- a/backend/code.c +++ b/backend/code.c @@ -259,7 +259,7 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[]) int i, error_number; unsigned int h, count, check_digit; - char localstr[8], checkstr[3]; + char localstr[10], checkstr[3]; int zeroes; error_number = 0; @@ -371,19 +371,20 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) strcpy(buffer, ""); int ascii_value; char dest[1000]; + unsigned char local_source[47]; error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 45) { + if(ustrlen(local_source) > 45) { /* This stops rediculously long input - the actual length of the barcode depends on the type of data */ strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - for(i = 0; i < ustrlen(source); i++) { - if(source[i] > 127) { + for(i = 0; i < ustrlen(local_source); i++) { + if(local_source[i] > 127) { /* Cannot encode extended ASCII */ strcpy(symbol->errtxt, "Invalid characters in input data"); return ERROR_INVALID_DATA; @@ -394,8 +395,8 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) concat(dest, "111141"); /* Message Content */ - for(i = 0; i < ustrlen(source); i++) { - ascii_value = source[i]; + for(i = 0; i < ustrlen(local_source); i++) { + ascii_value = local_source[i]; if(ascii_value == symbol->nullchar) { concat(buffer, C93Ctrl[0]); } else { @@ -463,12 +464,12 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) /* Stop character */ concat(dest, "1111411"); - h = ustrlen(source); - source[h] = set_copy[c]; - source[h + 1] = set_copy[k]; - source[h + 2] = '\0'; + h = ustrlen(local_source); + local_source[h] = set_copy[c]; + local_source[h + 1] = set_copy[k]; + local_source[h + 2] = '\0'; expand(symbol, dest); - ustrcpy(symbol->text, source); + ustrcpy(symbol->text, local_source); for(i = 0; i < ustrlen(symbol->text); i++) { if(symbol->text[i] == symbol->nullchar) { symbol->text[i] = ' '; diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 45b3f7ce..ac7031d5 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -43,11 +43,11 @@ void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[ input_length = ustrlen(source); char xor_register[17]; #ifndef _MSC_VER - char precrc_bitstream[(input_length * 8) + 16]; - char precrc_bitstream_reversed[(input_length * 8) + 16]; + char precrc_bitstream[(input_length * 8) + 18]; + char precrc_bitstream_reversed[(input_length * 8) + 18]; #else - char* precrc_bitstream = (char*)_alloca((input_length * 8) + 16); - char* precrc_bitstream_reversed = (char*)_alloca((input_length * 8) + 16); + char* precrc_bitstream = (char*)_alloca((input_length * 8) + 18); + char* precrc_bitstream_reversed = (char*)_alloca((input_length * 8) + 18); #endif int machine_cycles; char input_bit, out1, out2, out3; diff --git a/backend/postal.c b/backend/postal.c index 69651e39..b0510221 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -206,7 +206,7 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[]) { /* Korean Postal Authority */ int total, h, loop, check, zeroes, error_number; - char localstr[7], checkstr[3], dest[80]; + char localstr[8], checkstr[3], dest[80]; error_number = 0; h = ustrlen(source); @@ -499,19 +499,16 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[]) int japan_post(struct zint_symbol *symbol, unsigned char source[]) { /* Japanese Postal Code (Kasutama Barcode) */ int input_length, error_number; - char pattern[65]; - int writer, loopey, inter_posn, i, inter_length, sum, check; + char pattern[69]; + int writer, loopey, inter_posn, i, sum, check; char check_char; + char inter[23]; input_length = ustrlen(source); - inter_length = input_length * 2; - if(inter_length < 20) { inter_length = 20; } #ifndef _MSC_VER - char inter[inter_length]; - char local_source[input_length]; + char local_source[input_length + 1]; #else - char* inter = (char*)_alloca(inter_length); - char* local_source = (char*)_alloca(inter_length); + char* local_source = (char*)_alloca(input_length + 1); #endif inter_posn = 0; @@ -526,11 +523,14 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[]) return error_number; } - for(i = 0; i < inter_length; i++) { + for(i = 0; i < 20; i++) { inter[i] = 'd'; /* Pad character CC4 */ } + inter[20] = '\0'; - for(i = 0; i < input_length; i++) { + i = 0; + inter_posn = 0; + do { if(((local_source[i] >= '0') && (local_source[i] <= '9')) || (local_source[i] == '-')) { inter[inter_posn] = local_source[i]; inter_posn++; @@ -551,7 +551,9 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[]) inter_posn += 2; } } - } + i++; + }while((i < input_length) && (inter_posn < 20)); + inter[20] = '\0'; strcpy(pattern, "13"); /* Start */