mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-18 23:11:11 +08:00
Merge pull request #172 from pacheco017/UnityPrintFloat-overflow-fixes
UnityPrintFloat overflow fixes. (Thanks pacheco017!)
This commit is contained in:
13
src/unity.c
13
src/unity.c
@@ -280,10 +280,19 @@ void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
|
|||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
#ifdef UNITY_FLOAT_VERBOSE
|
#ifdef UNITY_FLOAT_VERBOSE
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef UNITY_VERBOSE_NUMBER_MAX_LENGTH
|
||||||
|
# ifdef UNITY_DOUBLE_VERBOSE
|
||||||
|
# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 317
|
||||||
|
# else
|
||||||
|
# define UNITY_VERBOSE_NUMBER_MAX_LENGTH 47
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
void UnityPrintFloat(_UF number)
|
void UnityPrintFloat(_UF number)
|
||||||
{
|
{
|
||||||
char TempBuffer[32];
|
char TempBuffer[UNITY_VERBOSE_NUMBER_MAX_LENGTH + 1];
|
||||||
sprintf(TempBuffer, "%.6f", number);
|
snprintf(TempBuffer, sizeof(TempBuffer), "%.6f", number);
|
||||||
UnityPrint(TempBuffer);
|
UnityPrint(TempBuffer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ void tearDown(void);
|
|||||||
// - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
|
// - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
|
||||||
// - define UNITY_DOUBLE_TYPE to specify something other than double
|
// - define UNITY_DOUBLE_TYPE to specify something other than double
|
||||||
// - define UNITY_DOUBLE_VERBOSE to print floating point values in errors (uses sprintf)
|
// - define UNITY_DOUBLE_VERBOSE to print floating point values in errors (uses sprintf)
|
||||||
|
// - define UNITY_VERBOSE_NUMBER_MAX_LENGTH to change maximum length of printed numbers (used by sprintf)
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
||||||
|
|||||||
Reference in New Issue
Block a user