mirror of
https://git.code.sf.net/p/zint/code
synced 2026-05-01 19:55:29 +00:00
gs1_lint_parse_raw_caret: check that data of AIs with non-predefined
lengths are terminated with separators (unless last) (ticket #352, props Simon Resch)
This commit is contained in:
@@ -1414,7 +1414,7 @@ static int gs1_lint_parse_raw_caret(const unsigned char source[], const int leng
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (i < length) {
|
while (i < length) {
|
||||||
int data_start, data_max, on_separator;
|
int data_start, data_max, on_separator, is_predefined_len;
|
||||||
assert(ai_count < ai_max);
|
assert(ai_count < ai_max);
|
||||||
ai_locs[ai_count] = i;
|
ai_locs[ai_count] = i;
|
||||||
if (!gs1_lint_parse_ai(source, length, i, &ai, NULL /*min*/, &max)) {
|
if (!gs1_lint_parse_ai(source, length, i, &ai, NULL /*min*/, &max)) {
|
||||||
@@ -1426,6 +1426,7 @@ static int gs1_lint_parse_raw_caret(const unsigned char source[], const int leng
|
|||||||
}
|
}
|
||||||
ai_vals[ai_count] = ai;
|
ai_vals[ai_count] = ai;
|
||||||
ai_len = ai < 100 ? 2 : ai < 1000 ? 3 : 4;
|
ai_len = ai < 100 ? 2 : ai < 1000 ? 3 : 4;
|
||||||
|
is_predefined_len = gs1_predefined_len(source + ai_locs[ai_count]);
|
||||||
|
|
||||||
/* Following GS1 Syntax Engine tolerating superfluous FNC1s at end of AI data
|
/* Following GS1 Syntax Engine tolerating superfluous FNC1s at end of AI data
|
||||||
(for both final AI and AIs with predefined length) */
|
(for both final AI and AIs with predefined length) */
|
||||||
@@ -1437,9 +1438,10 @@ static int gs1_lint_parse_raw_caret(const unsigned char source[], const int leng
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
data_locs[ai_count] = data_start;
|
data_locs[ai_count] = data_start;
|
||||||
/* Only checking that have at least one char, and haven't exceeded max */
|
/* Only checking that have at least one char, haven't exceeded max, and have separator if not predefined */
|
||||||
on_separator = j < length && source[j] == separator;
|
on_separator = j < length && source[j] == separator;
|
||||||
if (j == data_start || (j + 1 == length && length > data_max && !on_separator)) {
|
if (j == data_start || (j + 1 == length && length > data_max && !on_separator)
|
||||||
|
|| (j + 1 < length && !on_separator && !is_predefined_len)) {
|
||||||
*p_ai_count = ai_count; /* For feedback */
|
*p_ai_count = ai_count; /* For feedback */
|
||||||
data_lens[ai_count] = j - data_start;
|
data_lens[ai_count] = j - data_start;
|
||||||
*p_err_no = 2;
|
*p_err_no = 2;
|
||||||
|
|||||||
@@ -3421,6 +3421,9 @@ static void test_gs1_lint_parse_raw_caret(const testCtx *const p_ctx) {
|
|||||||
/* 44*/ { "^2551234567890128^39401234^4101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 1, 18, 27, 0 }, { 4, 22, 30, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
/* 44*/ { "^2551234567890128^39401234^4101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 1, 18, 27, 0 }, { 4, 22, 30, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
||||||
/* 45*/ { "2551234567890128\03539401234\0354101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 0, 17, 26, 0 }, { 3, 21, 29, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
/* 45*/ { "2551234567890128\03539401234\0354101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 0, 17, 26, 0 }, { 3, 21, 29, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
||||||
/* 46*/ { "\0352551234567890128\03539401234\0354101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 1, 18, 27, 0 }, { 4, 22, 30, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
/* 46*/ { "\0352551234567890128\03539401234\0354101234567890128", 1, 3, { 255, 3940, 410, 0 }, { 1, 18, 27, 0 }, { 4, 22, 30, 0 }, { 13, 4, 13, 0 }, 0, 0 },
|
||||||
|
/* 47*/ { "1012345678901234567890211", 0, 0, { 10, 0, 0, 0 }, { 0, 0, 0, 0 }, { 2, 0, 0, 0 }, { 20, 0, 0, 0 }, 2, 1 }, /* Ticket #352, props Simon Resch */
|
||||||
|
/* 48*/ { "^1012345678901234567890^211", 1, 2, { 10, 21, 0, 0 }, { 1, 24, 0, 0 }, { 3, 26, 0, 0 }, { 20, 1, 0, 0 }, 0, 0 },
|
||||||
|
/* 49*/ { "1012345678901234567890\035211", 1, 2, { 10, 21, 0, 0 }, { 0, 23, 0, 0 }, { 2, 25, 0, 0 }, { 20, 1, 0, 0 }, 0, 0 },
|
||||||
};
|
};
|
||||||
const int data_size = ARRAY_SIZE(data);
|
const int data_size = ARRAY_SIZE(data);
|
||||||
int i, length, ret;
|
int i, length, ret;
|
||||||
|
|||||||
@@ -666,7 +666,7 @@ $tab{$tab}return 0;
|
|||||||
{$tab}}
|
{$tab}}
|
||||||
|
|
||||||
{$tab}while (i < length) {
|
{$tab}while (i < length) {
|
||||||
$tab{$tab}int data_start, data_max, on_separator;
|
$tab{$tab}int data_start, data_max, on_separator, is_predefined_len;
|
||||||
$tab{$tab}assert(ai_count < ai_max);
|
$tab{$tab}assert(ai_count < ai_max);
|
||||||
$tab{$tab}ai_locs[ai_count] = i;
|
$tab{$tab}ai_locs[ai_count] = i;
|
||||||
$tab{$tab}if (!gs1_lint_parse_ai(source, length, i, &ai, NULL /*min*/, &max)) {
|
$tab{$tab}if (!gs1_lint_parse_ai(source, length, i, &ai, NULL /*min*/, &max)) {
|
||||||
@@ -678,6 +678,7 @@ $tab$tab{$tab}return 0;
|
|||||||
$tab{$tab}}
|
$tab{$tab}}
|
||||||
$tab{$tab}ai_vals[ai_count] = ai;
|
$tab{$tab}ai_vals[ai_count] = ai;
|
||||||
$tab{$tab}ai_len = ai < 100 ? 2 : ai < 1000 ? 3 : 4;
|
$tab{$tab}ai_len = ai < 100 ? 2 : ai < 1000 ? 3 : 4;
|
||||||
|
$tab{$tab}is_predefined_len = gs1_predefined_len(source + ai_locs[ai_count]);
|
||||||
|
|
||||||
$tab{$tab}/* Following GS1 Syntax Engine tolerating superfluous FNC1s at end of AI data
|
$tab{$tab}/* Following GS1 Syntax Engine tolerating superfluous FNC1s at end of AI data
|
||||||
$tab{$tab} (for both final AI and AIs with predefined length) */
|
$tab{$tab} (for both final AI and AIs with predefined length) */
|
||||||
@@ -689,9 +690,10 @@ $tab$tab$tab{$tab}break;
|
|||||||
$tab$tab{$tab}}
|
$tab$tab{$tab}}
|
||||||
$tab{$tab}}
|
$tab{$tab}}
|
||||||
$tab{$tab}data_locs[ai_count] = data_start;
|
$tab{$tab}data_locs[ai_count] = data_start;
|
||||||
$tab{$tab}/* Only checking that have at least one char, and haven't exceeded max */
|
$tab{$tab}/* Only checking that have at least one char, haven't exceeded max, and have separator if not predefined */
|
||||||
$tab{$tab}on_separator = j < length && source[j] == separator;
|
$tab{$tab}on_separator = j < length && source[j] == separator;
|
||||||
$tab{$tab}if (j == data_start || (j + 1 == length && length > data_max && !on_separator)) {
|
$tab{$tab}if (j == data_start || (j + 1 == length && length > data_max && !on_separator)
|
||||||
|
$tab{$tab}{$tab}{$tab}|| (j + 1 < length && !on_separator && !is_predefined_len)) {
|
||||||
$tab$tab{$tab}*p_ai_count = ai_count; /* For feedback */
|
$tab$tab{$tab}*p_ai_count = ai_count; /* For feedback */
|
||||||
$tab$tab{$tab}data_lens[ai_count] = j - data_start;
|
$tab$tab{$tab}data_lens[ai_count] = j - data_start;
|
||||||
$tab$tab{$tab}*p_err_no = 2;
|
$tab$tab{$tab}*p_err_no = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user