Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3cfa2f

Browse filesBrowse files
committed
Calling String::String(float ...) with +/- FLT_MAX or String::String(double ...) with +/- DBL_MAX results in a stack smashing.
1 parent 4bd75df commit f3cfa2f
Copy full SHA for f3cfa2f

File tree

1 file changed

+33
-7
lines changed
Filter options

1 file changed

+33
-7
lines changed

‎test/src/String/test_String.cpp

Copy file name to clipboardExpand all lines: test/src/String/test_String.cpp
+33-7Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* INCLUDE
77
**************************************************************************************/
88

9+
#include <float.h>
10+
911
#include <catch.hpp>
1012

1113
#include <String.h>
@@ -80,16 +82,40 @@ TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()
8082

8183
TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]")
8284
{
83-
float const val = 1.234f;
84-
arduino::String str(val);
85-
REQUIRE(strcmp(str.c_str(), "1.23") == 0);
85+
WHEN ("String::String (some float value)")
86+
{
87+
arduino::String str(1.234f);
88+
REQUIRE(strcmp(str.c_str(), "1.23") == 0);
89+
}
90+
WHEN ("String::String (FLT_MAX)")
91+
{
92+
arduino::String str(FLT_MAX);
93+
REQUIRE(strcmp(str.c_str(), "340282346638528859811704183484516925440.00") == 0);
94+
}
95+
WHEN ("String::String (-FLT_MAX)")
96+
{
97+
arduino::String str(-FLT_MAX);
98+
REQUIRE(strcmp(str.c_str(), "-340282346638528859811704183484516925440.00") == 0);
99+
}
86100
}
87101

88102
TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-11]")
89103
{
90-
double const val = 5.678;
91-
arduino::String str(val);
92-
REQUIRE(strcmp(str.c_str(), "5.68") == 0);
104+
WHEN ("String::String (some double value)")
105+
{
106+
arduino::String str(5.678);
107+
REQUIRE(strcmp(str.c_str(), "5.68") == 0);
108+
}
109+
WHEN ("String::String (DBL_MAX)")
110+
{
111+
arduino::String str(DBL_MAX);
112+
REQUIRE(strcmp(str.c_str(), "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0);
113+
}
114+
WHEN ("String::String (-DBL_MAX)")
115+
{
116+
arduino::String str(-DBL_MAX);
117+
REQUIRE(strcmp(str.c_str(), "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0);
118+
}
93119
}
94120

95121
TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid buffer", "[String-Ctor-12]")
@@ -131,4 +157,4 @@ TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smal
131157
arduino::String str1("Arduino");
132158
str = static_cast<arduino::String&&>(str1);
133159
REQUIRE(str1.compareTo("Arduino") == 0);
134-
}
160+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.