Avoid trying to encode non-EDIFACT characters in EDIFACT mode

Bug report by brunt, revokes commit [dc3626], tickets #44 and #50
This commit is contained in:
Robin Stuart 2016-11-26 20:10:51 +00:00
parent 0dc3b60c2b
commit 6115a3f8b6

View File

@ -432,13 +432,13 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
edf_count += (3.0F / 4.0F); // (p)(1)
} else {
if (inputData[sp] > 127) {
edf_count += (17.0F / 4.0F); // (p)(2)
edf_count += 17.0F; // (p)(2) > Value changed from ISO
} else {
edf_count += (13.0F / 4.0F); // (p)(3)
edf_count += 13.0F; // (p)(3) > Value changed from ISO
}
}
if ((gs1 == 1) && (inputData[sp] == '[')) {
edf_count += 6.0F;
edf_count += 13.0F; // > Value changed from ISO
}
/* base 256 ... step (q) */
@ -520,6 +520,9 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
}
}
//printf("Char %d[%c]: ASC:%.2f C40:%.2f X12:%.2f TXT:%.2f EDI:%.2f BIN:%.2f\n", sp,
// inputData[sp], ascii_count, c40_count, x12_count, text_count, edf_count, b256_count);
sp++;
} while (best_scheme == DM_NULL); // step (s)
@ -869,7 +872,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
/* step (f) EDIFACT encodation */
if (current_mode == DM_EDIFACT) {
int value = -1;
int value = 0;
next_mode = DM_EDIFACT;
if (*process_p == 3) {
@ -881,27 +884,15 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
(*process_p)++;
next_mode = DM_ASCII;
} else {
if ((source[sp] >= '@') && (source[sp] <= '^')) {
value = source[sp] - '@';
}
if ((source[sp] >= ' ') && (source[sp] <= '?')) {
value = source[sp];
}
if (value != -1) {
process_buffer[*process_p] = value;
(*process_p)++;
sp++;
} else {
// Invalid character, latch to ASCII
process_buffer[*process_p] = 31;
(*process_p)++;
value = source[sp];
while (*process_p < 4) {
process_buffer[*process_p] = 0;
(*process_p)++;
}
next_mode = DM_ASCII;
if (source[sp] >= 64) { // '@'
value -= 64;
}
process_buffer[*process_p] = value;
(*process_p)++;
sp++;
}
if (*process_p >= 4) {