-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Description
In short, strptime("2012/2/30", "%Y/%m/%d", &date) yields 2012/3/1 in emscripten while gcc a.c and musl-gcc a.c both give 2012/2/30. (Possibly UB though.)
Version of emscripten/emsdk:
$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.51-git (c0c2ca1314672a25699846b4663701bcb6f69cca)
clang version 18.0.0git (/startdir/llvm-project f2464ca317bfeeedddb7cbdea3c2c8ec487890bb)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/emscripten-llvm/binFailing command line in full:
// a.c
#include <stdio.h>
#include <time.h>
int main() {
struct tm date;
strptime("2012/2/30", "%Y/%m/%d", &date);
printf("%d/%d/%d\n", date.tm_year + 1900, date.tm_mon + 1, date.tm_mday);
return 0;
}$ emcc a.c
$ node a.out.js
2012/3/1In comparison, gcc a.c and musl-gcc a.c both give 2012/2/30.
Spec:
The POSIX spec does not seem to specify what to do when it encounters an invalid number that does not fit into the range, so this is possibly not a but but an undefined behavior instead? (But even if it is a UB, it really helps if emscripten follows the behavior of glibc/musl.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels