Skip to content

Commit

Permalink
Fix double-promotion in fprime codebase (#2818)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanBertrand committed Aug 16, 2024
1 parent 7159e7e commit 7bb161f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ add_compile_options(
-Wno-unused-parameter
)

# Add -Wshadow and -pedantic only for framework code, not the unit tests
# Add -Wshadow, -Wconversion and -pedantic only for framework code, not the unit tests
# TODO: uncomment -Wdouble-promotion once fpp is fixed
if (NOT BUILD_TESTING)
add_compile_options(
-Wshadow
-pedantic
-Wconversion
# -Wdouble-promotion
)
endif()

Expand Down
8 changes: 6 additions & 2 deletions Fw/Types/PolyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,16 @@ void PolyType::toString(StringBase& dest, bool append) const {
#endif
#if FW_HAS_F64
case TYPE_F64:
(void)snprintf(valString, sizeof(valString), "%lg ", this->m_val.f64Val);
(void)snprintf(valString, sizeof(valString), "%g ", this->m_val.f64Val);
break;
#endif
case TYPE_F32:
(void)snprintf(valString, sizeof(valString), "%g ", static_cast<F64>(this->m_val.f32Val));
break;
#else
case TYPE_F32:
(void)snprintf(valString, sizeof(valString), "%g ", this->m_val.f32Val);
break;
#endif
case TYPE_BOOL:
(void)snprintf(valString, sizeof(valString), "%s ", this->m_val.boolVal ? "T" : "F");
break;
Expand Down
2 changes: 1 addition & 1 deletion Fw/Types/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ FwSignedSizeType Fw::StringUtils::substring_find(const CHAR* source_string,
return -1;
}
// Confirm that the output type can hold the range of valid results
FW_ASSERT((source_size - sub_size) <= std::numeric_limits<FwSignedSizeType>::max());
FW_ASSERT(static_cast<FwSignedSizeType>(source_size - sub_size) <= std::numeric_limits<FwSignedSizeType>::max());

// Loop from zero to source_size - sub_size (inclusive)
for (FwSizeType source_index = 0;
Expand Down

0 comments on commit 7bb161f

Please sign in to comment.