raster/output: use new isfintf() to test floats integral (CodeQL)

This commit is contained in:
gitlost 2021-06-30 11:57:21 +01:00
parent 37fac73cb1
commit a312cd8e8e
5 changed files with 12 additions and 8 deletions

View File

@ -60,17 +60,21 @@
# if _MSC_VER < 1800 /* ceilf, floorf, roundf (C99) not before MSVC 2013 (C++ 12.0) */
# define ceilf (float) ceil
# define floorf (float) floor
# define roundf(arg) ((float) floor((arg) + 0.5f))
# define roundf (float) round
# define fmodf (float) fmod
# if _MSC_VER == 1200 /* VC6 */
# define round(arg) floor((arg) + 0.5f)
# endif
# endif
# pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER >= 1900 /* MSVC 2015 */
# if _MSC_VER >= 1800 /* MSVC 2013 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */
# endif
#endif
/* Is float integral value? (https://stackoverflow.com/a/40404149/664741) */
#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
#if (defined(__GNUC__) || defined(__clang__)) && !defined(ZINT_TEST) && !defined(__MINGW32__)
# define INTERNAL __attribute__ ((visibility ("hidden")))
#elif defined(ZINT_TEST)

View File

@ -540,7 +540,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i]) {
fixed_height += symbol->row_height[i];
if (!round_rows && si && symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) {
if (!round_rows && si && !isfintf(symbol->row_height[i] * si)) {
round_rows = 1;
}
} else {
@ -554,7 +554,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
large_bar_height = 0.01f; /* Token positive value */
symbol->height = large_bar_height * zero_count + fixed_height;
}
if (si && large_bar_height * si != (int) (large_bar_height * si)) {
if (si && !isfintf(large_bar_height * si)) {
large_bar_height = roundf(large_bar_height * si) / si;
symbol->height = large_bar_height * zero_count + fixed_height;
}
@ -564,7 +564,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
if (round_rows) {
fixed_height = 0.0f;
for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i] * si != (int) (symbol->row_height[i] * si)) {
if (!isfintf(symbol->row_height[i] * si)) {
symbol->row_height[i] = roundf(symbol->row_height[i] * si) / si;
}
fixed_height += symbol->row_height[i];

View File

@ -938,7 +938,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
scaler = 0.5f;
}
/* If half-integer scaling, then set integer scaler `si` to avoid scaling at end */
half_int_scaling = scaler * 2.0f == (int) (scaler * 2.0f);
half_int_scaling = isfintf(scaler * 2.0f);
if (half_int_scaling) {
si = (int) (scaler * 2.0f);
} else {

View File

@ -77,7 +77,7 @@ extern int assertionFailed;
extern int assertionNum;
extern const char *assertionFilename;
#if _MSC_VER == 1200 /* VC6 */
#if _MSC_VER < 1900 /* MSVC 2015 */
#define testStart(__arg__) (testStartReal("", __arg__))
#else
#define testStart(__arg__) (testStartReal(__func__, __arg__))

View File

@ -31,7 +31,7 @@
#include <malloc.h>
#include "../getopt/getopt.h"
#include "zint.h"
#if _MSC_VER >= 1900 /* MSVC 2015 */
#if _MSC_VER >= 1800 /* MSVC 2013 */
#pragma warning(disable: 4996) /* function or variable may be unsafe */
#endif
#endif /* _MSC_VER */