cisnan() warnings fix (#1008)
* Fix cisnan() macro warnings (strict-aliasing) * Hey, we found a bug thanks to our fix! Let's fix it too!
This commit is contained in:
parent
6456374eb8
commit
9f33df9574
|
@ -45,7 +45,19 @@ int indexOf(const char *string, char ch);
|
|||
float atoff(const char *string);
|
||||
int atoi(const char *string);
|
||||
|
||||
#if defined(__cplusplus) && defined(__OPTIMIZE__)
|
||||
#include <type_traits>
|
||||
// "g++ -O2" version, adds more strict type check and yet no "strict-aliasing" warnings!
|
||||
#define cisnan(f) ({ \
|
||||
static_assert(sizeof(f) == sizeof(int32_t)); \
|
||||
union cisnanu_t { std::remove_reference_t<decltype(f)> __f; int32_t __i; } __cisnan_u = { f }; \
|
||||
__cisnan_u.__i == 0x7FC00000; \
|
||||
})
|
||||
#else
|
||||
// "g++ -O0" or other C++/C compilers
|
||||
#define cisnan(f) (*(((int*) (&f))) == 0x7FC00000)
|
||||
#endif /* __cplusplus && __OPTIMIZE__ */
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
int absI(int32_t value);
|
||||
|
|
|
@ -46,7 +46,8 @@ int needInterpolationLogging(void);
|
|||
*/
|
||||
template<typename kType>
|
||||
int findIndexMsgExt(const char *msg, const kType array[], int size, kType value) {
|
||||
if (cisnan(value)) {
|
||||
float fvalue = (float)value;
|
||||
if (cisnan(fvalue)) {
|
||||
firmwareError(ERROR_NAN_FIND_INDEX, "NaN in findIndex%s", msg);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue