mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Segmentation fault for little or no data
This commit is contained in:
parent
fd45a1d277
commit
437cfb823d
@ -514,6 +514,31 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
|
||||
} while (exit_status == 0);
|
||||
|
||||
if(current_row == 0) {
|
||||
/* fill up the first row */
|
||||
for(c = column_position; c <= *(columns_needed); c++) {
|
||||
if(current_mode == MODEA) {
|
||||
blockmatrix[current_row][c] = 100; /* Code B */
|
||||
current_mode = MODEB;
|
||||
} else {
|
||||
blockmatrix[current_row][c] = 101; /* Code A */
|
||||
current_mode = MODEA;
|
||||
}
|
||||
}
|
||||
current_row++;
|
||||
/* add a second row */
|
||||
subset_selector[current_row] = MODEA;
|
||||
current_mode = MODEA;
|
||||
for(c = 0; c <= *(columns_needed) - 2; c++) {
|
||||
if(current_mode == MODEA) {
|
||||
blockmatrix[current_row][c] = 100; /* Code B */
|
||||
current_mode = MODEB;
|
||||
} else {
|
||||
blockmatrix[current_row][c] = 101; /* Code A */
|
||||
current_mode = MODEA;
|
||||
}
|
||||
}
|
||||
}
|
||||
*(rows_needed) = current_row + 1;
|
||||
|
||||
return error_number;
|
||||
@ -602,7 +627,6 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
|
||||
min_module_height = (0.55 * (columns_needed + 3)) + 3;
|
||||
if(min_module_height < 8) { min_module_height = 8; }
|
||||
|
||||
|
||||
/* Encode the Row Indicator in the First Row of the Symbol - Table D2 */
|
||||
if(subset_selector[0] == 99) {
|
||||
/* Code C */
|
||||
@ -643,6 +667,13 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
|
||||
for(i = 0; i < rows_needed; i++) {
|
||||
int writer, flip_flop;
|
||||
|
||||
printf("row %d: ",i);
|
||||
printf("103 %d %d [", subset_selector[i], row_indicator[i]);
|
||||
for(j = 0; j < columns_needed; j++) {
|
||||
printf("%d ",blockmatrix[i][j]);
|
||||
}
|
||||
printf("] %d 106\n", row_check[i]);
|
||||
|
||||
strcpy(row_pattern, "");
|
||||
/* Start character */
|
||||
concat(row_pattern, C128Table[103]); /* Always Start A */
|
||||
@ -650,18 +681,14 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
|
||||
concat(row_pattern, C128Table[subset_selector[i]]);
|
||||
concat(row_pattern, C128Table[row_indicator[i]]);
|
||||
|
||||
/*printf("103 %d %d ", subset_selector[i], row_indicator[i]);*/
|
||||
|
||||
for(j = 0; j < columns_needed; j++) {
|
||||
concat(row_pattern, C128Table[blockmatrix[i][j]]);
|
||||
/*printf("%d ",blockmatrix[i][j]);*/
|
||||
}
|
||||
|
||||
concat(row_pattern, C128Table[row_check[i]]);
|
||||
|
||||
/* Stop character */
|
||||
concat(row_pattern, C128Table[106]);
|
||||
/*printf("%d 106\n", row_check[i]);*/
|
||||
|
||||
/* Write the information into the symbol */
|
||||
writer = 0;
|
||||
|
@ -275,6 +275,10 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
rows_needed = (i/5);
|
||||
if(i%5 > 0) { rows_needed++; }
|
||||
|
||||
if(rows_needed == 1) {
|
||||
rows_needed = 2;
|
||||
}
|
||||
|
||||
/* start with the mode character - Table 2 */
|
||||
m = 0;
|
||||
switch(set[0]) {
|
||||
@ -393,16 +397,19 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
}
|
||||
} while (read < ustrlen(source));
|
||||
|
||||
|
||||
pads_needed = 5 - ((bar_characters + 2) % 5);
|
||||
if(pads_needed == 5) {
|
||||
pads_needed = 0;
|
||||
}
|
||||
if((bar_characters + pads_needed) < 8) {
|
||||
pads_needed += 8 - (bar_characters + pads_needed);
|
||||
}
|
||||
for(i = 0; i < pads_needed; i++) {
|
||||
values[bar_characters] = 106;
|
||||
bar_characters++;
|
||||
}
|
||||
|
||||
/* Calculate check digits */
|
||||
first_sum = 0;
|
||||
second_sum = 0;
|
||||
for(i = 0; i < bar_characters; i++)
|
||||
@ -424,6 +431,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[])
|
||||
concat(width_pattern, "1");
|
||||
for(i = 0; i < 5; i++) {
|
||||
concat(width_pattern, C16KTable[values[(current_row * 5) + i]]);
|
||||
|
||||
}
|
||||
concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]);
|
||||
|
||||
|
@ -137,8 +137,13 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input)
|
||||
int error_number, error_buffer;
|
||||
error_number = 0;
|
||||
|
||||
/* First check the symbology field */
|
||||
if(ustrlen(input) == 0) {
|
||||
strcpy(symbol->errtxt, "No input data [Z00]");
|
||||
error_tag(symbol->errtxt, ERROR_INVALID_DATA);
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
/* First check the symbology field */
|
||||
if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128 [Z01]"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; }
|
||||
|
||||
/* symbol->symbologys 1 to 86 are defined by tbarcode */
|
||||
@ -262,11 +267,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input)
|
||||
case BARCODE_DAFT: error_number = daft_code(symbol, input); break;
|
||||
case BARCODE_EAN14: error_number = ean_14(symbol, input); break;
|
||||
}
|
||||
|
||||
if(error_number == 0) {
|
||||
error_number = error_buffer;
|
||||
}
|
||||
|
||||
error_tag(symbol->errtxt, error_number);
|
||||
return error_number;
|
||||
}
|
||||
@ -318,6 +321,7 @@ int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle)
|
||||
output[2] = symbol->outfile[strlen(symbol->outfile) - 1];
|
||||
output[3] = '\0';
|
||||
to_upper((unsigned char*)output);
|
||||
|
||||
#ifndef NO_PNG
|
||||
if(!(strcmp(output, "PNG"))) {
|
||||
error_number = png_handle(symbol, rotate_angle);
|
||||
|
Loading…
Reference in New Issue
Block a user