emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

When I use fflush(stdin), the output is wrong. Is it a bug?

Open laudedd opened this issue 1 year ago • 1 comments

Source code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
    int a,b;
    while( scanf("%d %d",&a,&b)!=EOF){
        fflush(stdin);
        printf("%d %d\n", a, b);
    }
 return 0;   
}

In input.txt:

1 2
3 4
5 6

Run with "wasmtime a.wasm < input.txt" or "wasmer a.wasm < input.txt", the output is:

1 2

Is it a bug?

laudedd avatar Apr 20 '24 07:04 laudedd

Looks like probably an emscripten bug yes. Something to do with the stdin handling most likely.

You can repro this without wasmtime or wasmer:

$ emcc test.c
node ./a.out.js < input.txt 
1 2

Surprisingly it also occurs with -sNODERAWFS which normally bypasses any bugs in the emscripten FS layers.

sbc100 avatar Apr 20 '24 22:04 sbc100