Change height and row_height array to floats: VC6, CodeQL fixes

This commit is contained in:
gitlost 2021-06-20 00:05:45 +01:00
parent c693482aa1
commit e5115bad07
8 changed files with 15 additions and 17 deletions

View File

@ -640,7 +640,7 @@ INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int l
int emptyColumns; int emptyColumns;
char dest[1000]; char dest[1000];
int r, c; int r, c;
float min_row_height; float min_row_height = 0.0f;
#ifdef _MSC_VER #ifdef _MSC_VER
CharacterSetTable *T; CharacterSetTable *T;
unsigned char *data; unsigned char *data;
@ -997,8 +997,7 @@ INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int l
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f, error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/); 0 /*no_errtxt*/);
#else #else
(void)min_row_height; (void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif #endif
symbol->output_options |= BARCODE_BIND; symbol->output_options |= BARCODE_BIND;

View File

@ -120,7 +120,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
int input_length; int input_length;
int gs1, c_count; int gs1, c_count;
int separator; int separator;
float min_row_height; float min_row_height = 0.0f;
/* Suppresses clang-analyzer-core.UndefinedBinaryOperatorResult warning on fset which is fully set */ /* Suppresses clang-analyzer-core.UndefinedBinaryOperatorResult warning on fset which is fully set */
assert(length > 0); assert(length > 0);
@ -500,8 +500,8 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f, error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/); 0 /*no_errtxt*/);
#else #else
(void)min_row_height; (void)separator; (void)&separator;
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); (void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif #endif
symbol->output_options |= BARCODE_BIND; symbol->output_options |= BARCODE_BIND;

View File

@ -50,7 +50,7 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
int gs1; int gs1;
int h, len; int h, len;
int separator; int separator;
float min_row_height; float min_row_height = 0.0f;
int error_number = 0; int error_number = 0;
if (length > 81) { if (length > 81) {
@ -358,8 +358,8 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f, error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/); 0 /*no_errtxt*/);
#else #else
(void)min_row_height; (void)separator; (void)&separator;
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); (void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif #endif
symbol->output_options |= BARCODE_BIND; symbol->output_options |= BARCODE_BIND;

View File

@ -64,6 +64,9 @@
# define ceilf (float) ceil # define ceilf (float) ceil
# define floorf (float) floor # define floorf (float) floor
# define roundf(arg) ((float) floor((arg) + 0.5f)) # define roundf(arg) ((float) floor((arg) + 0.5f))
# if _MSC_VER == 1200 /* VC6 */
# define round(arg) floor((arg) + 0.5f)
# endif
# endif # endif
# pragma warning(disable: 4244) /* conversion from int to float */ # pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER >= 1900 /* MSVC 2015 */ # if _MSC_VER >= 1900 /* MSVC 2015 */

View File

@ -555,7 +555,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
symbol->height = large_bar_height * zero_count + fixed_height; symbol->height = large_bar_height * zero_count + fixed_height;
} }
if (si && large_bar_height * si != (int) (large_bar_height * si)) { if (si && large_bar_height * si != (int) (large_bar_height * si)) {
large_bar_height = (float) (round(large_bar_height * si) / si); large_bar_height = roundf(large_bar_height * si) / si;
symbol->height = large_bar_height * zero_count + fixed_height; symbol->height = large_bar_height * zero_count + fixed_height;
} }
/* Note should never happen that have both zero_count and round_rows */ /* Note should never happen that have both zero_count and round_rows */
@ -565,7 +565,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
fixed_height = 0.0f; fixed_height = 0.0f;
for (i = 0; i < symbol->rows; i++) { for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) { if (symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) {
symbol->row_height[i] = (float) (round(symbol->row_height[i] * si) / si); symbol->row_height[i] = roundf(symbol->row_height[i] * si) / si;
} }
fixed_height += symbol->row_height[i]; fixed_height += symbol->row_height[i];
} }

View File

@ -35,10 +35,6 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
/* For Visual C++ 6 suppress conversion from int to float warning */
#if _MSC_VER == 1200
#pragma warning(disable: 4244)
#endif
#endif #endif
#include "common.h" #include "common.h"