mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
raster/output: use new isfintf() to test floats integral (CodeQL)
This commit is contained in:
parent
37fac73cb1
commit
a312cd8e8e
@ -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)
|
||||
|
@ -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];
|
||||
|
@ -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 {
|
||||
|
@ -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__))
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user