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.
This commit is contained in:
Schaich 2021-11-23 20:04:56 +09:00
parent 9e4ecb638f
commit 609fbeb008

View File

@ -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++);