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

Commit6197511

Browse files
committed
Avoid overflowing parseFloat()'s internal 'value'
If more than 309 digits are provided to Stream::parseFloat() (more than39 on AVR), the internal variable 'value' would overflow to infinity. Weavoid this by not storing the parsed number as an integer-in-a-float.
1 parent91c5e29 commit6197511

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎api/Stream.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,12 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
179179
elseif (c =='.')
180180
isFraction =true;
181181
elseif(c >='0' && c <='9') {// is c a digit?
182-
value = value *10 + c -'0';
183-
if(isFraction)
184-
fraction *=0.1;
182+
if(isFraction) {
183+
fraction *=0.1;
184+
value = value + fraction * (c -'0');
185+
}else {
186+
value = value *10 + c -'0';
187+
}
185188
}
186189
read();// consume the character we got with peek
187190
c =timedPeek();
@@ -191,9 +194,6 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
191194
if(isNegative)
192195
value = -value;
193196

194-
if(isFraction)
195-
value *= fraction;
196-
197197
return value;
198198
}
199199

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp