From 27c7c9447ccf8948419048d2abf527d3b6d0254e Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 10 Jan 2016 13:24:25 +0000 Subject: [PATCH] Avoid segfault generating DataBar Stacked Do not read element values which have not been initialised when stacking symbol Fixes #6 --- backend/rss.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/rss.c b/backend/rss.c index 18272952..1a9e199c 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -2121,8 +2121,10 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) left_to_right = 1; i = 2 + (current_block * 21); for(j = 0; j < 21; j++) { - sub_elements[j + (reader * 21) + 2] = elements[i + j]; - elements_in_sub++; + if((i + j) < pattern_width) { + sub_elements[j + (reader * 21) + 2] = elements[i + j]; + elements_in_sub++; + } } } else { /* right to left */ @@ -2131,8 +2133,10 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) /* a full row */ i = 2 + (((current_row * symbol->option_2) - reader - 1) * 21); for(j = 0; j < 21; j++) { - sub_elements[(20 - j) + (reader * 21) + 2] = elements[i + j]; - elements_in_sub++; + if((i + j) < pattern_width) { + sub_elements[(20 - j) + (reader * 21) + 2] = elements[i + j]; + elements_in_sub++; + } } } else { /* a partial row */ @@ -2140,8 +2144,10 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) l = (current_row * symbol->option_2) - reader - 1; i = 2 + ((l - k) * 21); for(j = 0; j < 21; j++) { - sub_elements[(20 - j) + (reader * 21) + 2] = elements[i + j]; - elements_in_sub++; + if((i + j) < pattern_width) { + sub_elements[(20 - j) + (reader * 21) + 2] = elements[i + j]; + elements_in_sub++; + } } } }