Correct some memory leaks found by MSVC

This commit is contained in:
hooper114 2009-06-18 10:20:23 +00:00
parent 6c631bf282
commit 18b986156f
10 changed files with 60 additions and 35 deletions

View File

@ -55,11 +55,11 @@ int aztec_text_process(unsigned char source[], char binary_string[], int gs1)
int i, j, k, bytes; int i, j, k, bytes;
int curtable, newtable, lasttable, chartype, maplength, blocks, debug; int curtable, newtable, lasttable, chartype, maplength, blocks, debug;
#ifndef _MSC_VER #ifndef _MSC_VER
int charmap[ustrlen(source)], typemap[ustrlen(source)]; int charmap[ustrlen(source) * 2], typemap[ustrlen(source) * 2];
int blockmap[2][ustrlen(source)]; int blockmap[2][ustrlen(source)];
#else #else
int* charmap = (int*)_alloca(ustrlen(source) * sizeof(int)); int* charmap = (int*)_alloca((ustrlen(source) * 2) * sizeof(int));
int* typemap = (int*)_alloca(ustrlen(source) * sizeof(int)); int* typemap = (int*)_alloca((ustrlen(source) * 2) * sizeof(int));
int* blockmap[2]; int* blockmap[2];
blockmap[0] = (int*)_alloca(ustrlen(source) * sizeof(int)); blockmap[0] = (int*)_alloca(ustrlen(source) * sizeof(int));
blockmap[1] = (int*)_alloca(ustrlen(source) * sizeof(int)); blockmap[1] = (int*)_alloca(ustrlen(source) * sizeof(int));

View File

@ -241,7 +241,7 @@ static char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111" "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
}; };
static char *pentbit[32] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", static char *pentbit[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
"1010", "1011", "1100", "1101", "1110", "1111" "1010", "1011", "1100", "1101", "1110", "1111"
}; };

View File

@ -169,10 +169,12 @@ int c39(struct zint_symbol *symbol, unsigned char source[])
char check_digit; char check_digit;
int h, error_number; int h, error_number;
char dest[1000]; char dest[1000];
char localstr[3];
error_number = 0; error_number = 0;
counter = 0; counter = 0;
strcpy(dest, ""); strcpy(dest, "");
strcpy(localstr, "");
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) { if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
symbol->option_2 = 0; symbol->option_2 = 0;
@ -226,8 +228,8 @@ int c39(struct zint_symbol *symbol, unsigned char source[])
} }
h = ustrlen(source); h = ustrlen(source);
source[h] = check_digit; localstr[0] = check_digit;
source[h + 1] = '\0'; localstr[1] = '\0';
} }
/* Stop character */ /* Stop character */
@ -247,9 +249,11 @@ int c39(struct zint_symbol *symbol, unsigned char source[])
if(symbol->symbology == BARCODE_CODE39) { if(symbol->symbology == BARCODE_CODE39) {
ustrcpy(symbol->text, (unsigned char*)"*"); ustrcpy(symbol->text, (unsigned char*)"*");
uconcat(symbol->text, source); uconcat(symbol->text, source);
uconcat(symbol->text, (unsigned char*)localstr);
uconcat(symbol->text, (unsigned char*)"*"); uconcat(symbol->text, (unsigned char*)"*");
} else { } else {
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
uconcat(symbol->text, (unsigned char*)localstr);
} }
return error_number; return error_number;
} }

View File

@ -92,7 +92,7 @@ int is_sane(char test_string[], unsigned char source[])
{ /* Verifies that a string only uses valid characters */ { /* Verifies that a string only uses valid characters */
unsigned int i, j, latch; unsigned int i, j, latch;
for(i = 0; i < ustrlen(source); i++) { for(i = 0; i < ustrlen(source) - 1; i++) {
latch = FALSE; latch = FALSE;
for(j = 0; j < strlen(test_string); j++) { for(j = 0; j < strlen(test_string); j++) {
if (source[i] == test_string[j]) { latch = TRUE; } } if (source[i] == test_string[j]) { latch = TRUE; } }
@ -231,6 +231,19 @@ int is_stackable(int symbology) {
return 0; return 0;
} }
int is_extendable(int symbology) {
/* Indicates which symbols can have addon */
if(symbology == BARCODE_EANX) { return 1; }
if(symbology == BARCODE_UPCA) { return 1; }
if(symbology == BARCODE_UPCE) { return 1; }
if(symbology == BARCODE_ISBNX) { return 1; }
if(symbology == BARCODE_UPCA_CC) { return 1; }
if(symbology == BARCODE_UPCE_CC) { return 1; }
if(symbology == BARCODE_EANX_CC) { return 1; }
return 0;
}
int roundup(float input) int roundup(float input)
{ {
float remainder; float remainder;

View File

@ -53,6 +53,7 @@ extern void lookup(char set_string[], char *table[], char data, char dest[]);
extern int posn(char set_string[], char data); extern int posn(char set_string[], char data);
extern void expand(struct zint_symbol *symbol, char data[]); extern void expand(struct zint_symbol *symbol, char data[]);
extern int is_stackable(int symbology); extern int is_stackable(int symbology);
extern int is_extendable(int symbology);
extern int roundup(float input); extern int roundup(float input);
extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord); extern int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord);
extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord);

View File

@ -389,6 +389,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source)
int input_length; int input_length;
input_length = ustrlen(source); input_length = ustrlen(source);
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char preprocessed[input_length]; unsigned char preprocessed[input_length];
#else #else
@ -595,7 +596,7 @@ int ZBarcode_Print(struct zint_symbol *symbol)
/* int i, j; /* int i, j;
for(i = 0; i < symbol->rows; i++) { for(i = 0; i < symbol->rows; i++) {
for(j = 0; j < symbol->width / 7; j++) { for(j = 0; j <= symbol->width / 7; j++) {
printf("%2.2X ", symbol->encoded_data[i][j]); printf("%2.2X ", symbol->encoded_data[i][j]);
} }
printf("\n"); printf("\n");

View File

@ -555,13 +555,15 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle)
latch = 0; latch = 0;
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
for(i = 0; i < ustrlen(local_text); i++) { if(is_extendable(symbol->symbology)) {
if (latch == 1) { for(i = 0; i < ustrlen(local_text); i++) {
addon[r] = local_text[i]; if (latch == 1) {
r++; addon[r] = local_text[i];
} r++;
if (symbol->text[i] == '+') { }
latch = 1; if (symbol->text[i] == '+') {
latch = 1;
}
} }
} }
addon[r] = '\0'; addon[r] = '\0';

View File

@ -154,13 +154,15 @@ int ps_plot(struct zint_symbol *symbol)
latch = 0; latch = 0;
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
for(i = 0; i < ustrlen(symbol->text); i++) { if(is_extendable(symbol->symbology)) {
if (latch == 1) { for(i = 0; i < ustrlen(symbol->text); i++) {
addon[r] = symbol->text[i]; if (latch == 1) {
r++; addon[r] = symbol->text[i];
} r++;
if (symbol->text[i] == '+') { }
latch = 1; if (symbol->text[i] == '+') {
latch = 1;
}
} }
} }
addon[r] = '\0'; addon[r] = '\0';

View File

@ -150,13 +150,15 @@ int svg_plot(struct zint_symbol *symbol)
latch = 0; latch = 0;
r = 0; r = 0;
/* Isolate add-on text */ /* Isolate add-on text */
for(i = 0; i < ustrlen(symbol->text); i++) { if(is_extendable(symbol->symbology)) {
if (latch == 1) { for(i = 0; i < ustrlen(symbol->text); i++) {
addon[r] = symbol->text[i]; if (latch == 1) {
r++; addon[r] = symbol->text[i];
} r++;
if (symbol->text[i] == '+') { }
latch = 1; if (symbol->text[i] == '+') {
latch = 1;
}
} }
} }
addon[r] = '\0'; addon[r] = '\0';

View File

@ -613,11 +613,11 @@ zint -o bar92.eps -b 92 --border=10 -d "Demonstration Aztec Code symbol generate
zint -o bar92.svg -b 92 --border=10 -d "Demonstration Aztec Code symbol generated by libzint" zint -o bar92.svg -b 92 --border=10 -d "Demonstration Aztec Code symbol generated by libzint"
echo zint -o bar92a.png -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231" zint -o bar92a.png -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231"
echo zint -o bar92a.eps -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231" zint -o bar92a.eps -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231"
echo zint -o bar92a.svg -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231" zint -o bar92a.svg -b 92 --gs1 --border=10 -d "[01]98898765432106[02]13012345678909[10]1234567ABCDEFG[3202]012345[15]991231"
echo testing DAFT Code echo testing DAFT Code