telepen_num: strcpy -> memcpy to ensure temp buffer filled (#270)

common: ensure stripf() not inlined to prevent optimizations undoing
  effect (#269), undo previous volatile temps workaround ([ac80b3])
This commit is contained in:
gitlost
2022-09-06 15:58:53 +01:00
parent ac80b33c3c
commit defb4587de
3 changed files with 46 additions and 41 deletions

View File

@ -488,10 +488,7 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
row_height = 0.5f;
}
if (min_row_height) {
/* This seems necessary to get gcc 12.2.1 to work consistently for static 32-bit builds */
volatile const float row_height_strip = stripf(row_height);
volatile const float min_row_height_strip = stripf(min_row_height);
if (row_height_strip < min_row_height_strip) {
if (stripf(row_height) < stripf(min_row_height)) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "247: Height not compliant with standards");
@ -503,10 +500,7 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
symbol->height = stripf(fixed_height); /* Ignore any given height */
}
if (max_height) {
/* See above */
volatile const float symbol_height_strip = stripf(symbol->height);
volatile const float max_height_strip = stripf(max_height);
if (symbol_height_strip > max_height_strip) {
if (stripf(symbol->height) > stripf(max_height)) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "248: Height not compliant with standards");
@ -517,6 +511,13 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
return error_number;
}
/* Prevent inlining of `stripf()` which can optimize away its effect */
#if defined(__GNUC__) || defined(__clang__)
__attribute__((__noinline__))
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1310 /* MSVC 2003 (VC++ 7.1) */
__declspec(noinline)
#endif
/* Removes excess precision from floats - see https://stackoverflow.com/q/503436 */
INTERNAL float stripf(const float arg) {
return *((volatile const float *) &arg);