| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Hrm, I'm disinclined to merge this because its a hack to fix something broken elsewhere the way it sounds, has this been reported to emscripten and confirmed? I don't have anything handy to test emscripten with but if it behaves as you say, its definitely an emscripten bug (or at least, not libRocket). I'd not be against merging it if it was wrapped in #ifdefs making it clear that it was a hack to fix a broken emscripten part. |
Sorry, something went wrong.
… emscripten-compiler emscripten's sscanf seems to have a problem parsing floats from strings like "10em". I guess emscripten expects another value after the e to be valid... this patch removes the suffix from the string before calling sscanf
|
I guess not even gcc/clang do handle this special case in a right manner but better than emscripten. I tested it with this code: #include <stdio.h>
#include <stdlib.h>
int main()
{
float floatVal;
char unit[20],dtm[20];
strcpy( dtm, "10.0em" );
sscanf( dtm, "%f%s", &floatVal,unit );
printf("value:%f unit:%s\n",floatVal,unit );
return(0);
}
gcc/clang do return: 10.0000 / 'm' (consuming the e-character) I posted the issue to emscripten and surrounded the hack with an #ifdef. |
Sorry, something went wrong.
|
hmm, okay, let me investigate some more and see whats going on. I may be misinterpreting the scanf parsing. Thanks for the updated patch, but with your example code I want to investigate a little more and find out exactly what the problem is and why it seems to work with gcc/llvm but your test code shows that it shouldn't. Stay tuned |
Sorry, something went wrong.
|
To be honest I didn't use scanf yet and usually when I come to the point that I'm sure there is a bug in a major framework, it is still me who is wrong. :) |
Sorry, something went wrong.
|
This looks like a duplicate of the problem I already fixed in librocket earlier but which was also not accepted. VS2015's scanf fails the same way without it. Surely they all can't be wrong. |
Sorry, something went wrong.
|
Emscripten and VS2015's scanf are correct conforming implementations, but gcc and llvm are wrong. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf Interpretation of format specifiers:
Parsting the format specifier:
Note that:
From strtod:
The grammar of a floating point number
Note that this grammar REQUIRES a number after the "e". So the parsing of "10em" will FAIL when using scanf() because it would need to support pushing 2 characters back onto the input stream instead of just 1. This code should be changed to use strtod. strtod is defined to parse a floating point number using:
So strtod() will work properly in this case. |
Sorry, something went wrong.
Co-authored-by: aquawicket <5370616+aquawicket@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
...scripten-compiler
emscripten's sscanf seems to have a problem parsing floats from strings like "10em".
I guess emscripten expects another value after the e to be valid... this patch removes
the suffix from the string before calling sscanf