Ensure ECI encoding doesn't corrupt binary data in Data Matrix

Fixes #105 reported by Daniel Gredler
This commit is contained in:
Robin Stuart 2018-06-20 23:47:06 +01:00
parent 8fcde380f8
commit 23a990c37c

View File

@ -581,12 +581,14 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
if (symbol->eci <= 126) { if (symbol->eci <= 126) {
target[tp] = (unsigned char) symbol->eci + 1; target[tp] = (unsigned char) symbol->eci + 1;
tp++; tp++;
strcat(binary, " ");
} }
if ((symbol->eci >= 127) && (symbol->eci <= 16382)) { if ((symbol->eci >= 127) && (symbol->eci <= 16382)) {
target[tp] = (unsigned char) ((symbol->eci - 127) / 254) + 128; target[tp] = (unsigned char) ((symbol->eci - 127) / 254) + 128;
tp++; tp++;
target[tp] = (unsigned char) ((symbol->eci - 127) % 254) + 1; target[tp] = (unsigned char) ((symbol->eci - 127) % 254) + 1;
tp++; tp++;
strcat(binary, " ");
} }
if (symbol->eci >= 16383) { if (symbol->eci >= 16383) {
target[tp] = (unsigned char) ((symbol->eci - 16383) / 64516) + 192; target[tp] = (unsigned char) ((symbol->eci - 16383) / 64516) + 192;
@ -595,6 +597,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
tp++; tp++;
target[tp] = (unsigned char) ((symbol->eci - 16383) % 254) + 1; target[tp] = (unsigned char) ((symbol->eci - 16383) % 254) + 1;
tp++; tp++;
strcat(binary, " ");
} }
if (debug) printf("ECI %d ", symbol->eci + 1); if (debug) printf("ECI %d ", symbol->eci + 1);
} }