Skip to content

Commit 6197511

Browse files
committed
Avoid overflowing parseFloat()'s internal 'value'
If more than 309 digits are provided to Stream::parseFloat() (more than 39 on AVR), the internal variable 'value' would overflow to infinity. We avoid this by not storing the parsed number as an integer-in-a-float.
1 parent 91c5e29 commit 6197511

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
else if (c == '.')
180180
isFraction = true;
181181
else if(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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy