From 609fbeb008ec1537da669affe5a1c138a63fceeb Mon Sep 17 00:00:00 2001 From: Schaich Date: Tue, 23 Nov 2021 20:04:56 +0900 Subject: [PATCH] Pull addon_row_height out of the loop The ```addon_row_height``` variable is conditionally initialized in some branches, which also set ```addon_latch``` to one(true). Later in the loop's body, ```addon_row_height``` is accessed if ```addon_latch``` is true. Unlike ```addon_row_height```, ```addon_latch``` is defined outside of the loop's body, and as it is never reset to zero, keeps it's value of one once it has been assigned. Future iterations of the loop can therefore not branch into the code that initializes ```addon_row_height``` and (re)assigns ```addon_latch```, and ```addon_latch``` will be true, which causes ```addon_row_height``` to be accessed without having been initialized. On most platforms, the ```addon_row_height``` variable will always be allocated on the same memory, while skipping the initialization causes the value that was previously assigned to ```addon_row_height``` to remain on that memory. Pull the variable declaration out of the for loop's body to assure the previous iteration's value remains there independend of compiler or platform specific behaviour. --- backend/vector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/vector.c b/backend/vector.c index c2c06943..193b8829 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -409,6 +409,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ int text_height; /* Font pixel size (so whole integers) */ float text_gap; /* Gap between barcode and text */ float guard_descent; + float addon_row_height; float large_bar_height; int upcae_outside_text_height = 0; /* UPC-A/E outside digits font size */ @@ -593,7 +594,6 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ last_row_start = rect_count; for (i = 0; i < symbol->width; i += block_width) { - float addon_row_height; const int fill = module_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) && module_is_set(symbol, r, i + block_width) == fill; block_width++);