Strip BOM from Unicode input data

Fixes #76, reported by Shmupsik
This commit is contained in:
Robin Stuart 2017-10-09 19:59:02 +01:00
parent 7f8a461f72
commit bfb183e5df

View File

@ -812,6 +812,20 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
return error_number; return error_number;
} }
void strip_bom(unsigned char *source, int *input_length) {
int i;
if (*input_length > 3) {
if((source[0] == 0xef) && (source[1] == 0xbb) && (source[2] == 0xbf)) {
/* BOM at start of input data, strip in accordance with RFC 3629 */
for (i = 3; i < *input_length; i++) {
source[i - 3] = source[i];
}
}
}
*input_length -= 3;
}
int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int in_length) { int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int in_length) {
int error_number, error_buffer, i; int error_number, error_buffer, i;
#ifdef _MSC_VER #ifdef _MSC_VER
@ -1017,6 +1031,10 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int
local_source[in_length] = '\0'; local_source[in_length] = '\0';
} }
if (symbol->input_mode == UNICODE_MODE) {
strip_bom(local_source, &in_length);
}
if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) { if ((symbol->dot_size < 0.01) || (symbol->dot_size > 20.0)) {
strcpy(symbol->errtxt, "221: Invalid dot size"); strcpy(symbol->errtxt, "221: Invalid dot size");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;