Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit754873c

Browse files
committed
Increase buffer size in order to avoid buffer overflow when using large floating point numbers
1 parentf3cfa2f commit754873c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

‎api/String.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include"itoa.h"
2424
#include"deprecated-avr-comp/avr/dtostrf.h"
2525

26+
#include<float.h>
27+
2628
/*********************************************/
2729
/* Constructors*/
2830
/*********************************************/
@@ -111,15 +113,17 @@ String::String(unsigned long value, unsigned char base)
111113

112114
String::String(float value,unsignedchar decimalPlaces)
113115
{
116+
staticsize_tconst FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES +1/* '-'*/ +1/* '.'*/ +1/* '\0'*/;
114117
init();
115-
char buf[33];
118+
char buf[FLOAT_BUF_SIZE];
116119
*this =dtostrf(value, (decimalPlaces +2), decimalPlaces, buf);
117120
}
118121

119122
String::String(double value,unsignedchar decimalPlaces)
120123
{
124+
staticsize_tconst DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES +1/* '-'*/ +1/* '.'*/ +1/* '\0'*/;
121125
init();
122-
char buf[33];
126+
char buf[DOUBLE_BUF_SIZE];
123127
*this =dtostrf(value, (decimalPlaces +2), decimalPlaces, buf);
124128
}
125129

‎api/String.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class String
5858
typedefvoid (String::*StringIfHelperType)()const;
5959
voidStringIfHelper()const {}
6060

61+
staticsize_tconst FLT_MAX_DECIMAL_PLACES =10;
62+
staticsize_tconst DBL_MAX_DECIMAL_PLACES = FLT_MAX_DECIMAL_PLACES;
63+
6164
public:
6265
// constructors
6366
// creates a copy of the initial value.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp