From f655eabc12e67ca5c3bb4db8ba521edf017d43ad Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sat, 10 Feb 2018 07:26:33 +0000 Subject: [PATCH] Add trailing spaces to Mailmark if not present in input data --- backend/mailmark.c | 23 +++++++++++++++++++---- docs/manual.txt | 4 +++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/mailmark.c b/backend/mailmark.c index c5f11c15..e15414fc 100644 --- a/backend/mailmark.c +++ b/backend/mailmark.c @@ -146,12 +146,27 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) { int check_count; int i, j; - if ((length != 22) && (length != 26)) { - strcpy(symbol->errtxt, "580: Invalid length input"); - return ZINT_ERROR_INVALID_DATA; + if (length > 26) { + strcpy(symbol->errtxt, "580: Input too long"); + return ZINT_ERROR_TOO_LONG; } strcpy(local_source, (char*) source); + + if (length < 22) { + for (i = length; i <= 22; i++) { + strcat(local_source, " "); + } + length = 22; + } + + if ((length > 22) && (length < 26)) { + for (i = length; i <= 26; i++) { + strcat(local_source, " "); + } + length = 26; + } + to_upper((unsigned char*) local_source); if (symbol->debug) { @@ -159,7 +174,7 @@ int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) { } if (is_sane(RUBIDIUM, (unsigned char *) local_source, length) != 0) { - strcpy(symbol->errtxt, "581: Invalid characters or format in input data"); + strcpy(symbol->errtxt, "581: Invalid characters in input data"); return ZINT_ERROR_INVALID_DATA; } diff --git a/docs/manual.txt b/docs/manual.txt index 4e1dcef5..00ffb407 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -1726,7 +1726,9 @@ generated by Zint. Developed in 2014 as a replacement for RM4SCC this 4-state symbol includes Reed Solomon error correction. Input is a pre-formatted alpanumeric string of 22 (for Barcode C) or 26 (for Barcode L) characters, producing a symbol with -66 or 78 bars respectively. +66 or 78 bars respectively. Some of the permitted inputs include a number of +trailing space characters - these will be appended by Zint if not included in +the input data. 6.5.5 USPS OneCode ------------------