standalone: Use fgets() instead of getline() for reading

getline() is incorrect (it can reallocate)
This commit is contained in:
Remko Tronçon 2022-10-08 08:36:26 +02:00
parent 371ab4c6a7
commit e7a45f5b0c
2 changed files with 4 additions and 7 deletions

View file

@ -21,7 +21,7 @@ jobs:
- run: make -C src/standalone check - run: make -C src/standalone check
- name: "Upload artifacts" - name: "Upload artifacts"
run: | run: |
for f in src/standalone/waforth-*.tgz; do for f in `find src/standalone -name 'waforth-*.tgz' -o -name 'waforth-*.zip'`; do
curl --fail \ curl --fail \
-H "Authorization: token $GITHUB_TOKEN" \ -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: $(file -b --mime-type $f)" \ -H "Content-Type: $(file -b --mime-type $f)" \

View file

@ -52,14 +52,11 @@ wasm_trap_t *emit_cb(const wasm_val_vec_t *args, wasm_val_vec_t *results) {
} }
wasm_trap_t *read_cb(const wasm_val_vec_t *args, wasm_val_vec_t *results) { wasm_trap_t *read_cb(const wasm_val_vec_t *args, wasm_val_vec_t *results) {
int n = 0;
char *addr = &wasm_memory_data(memory)[args->data[0].of.i32]; char *addr = &wasm_memory_data(memory)[args->data[0].of.i32];
size_t len = args->data[1].of.i32; size_t len = args->data[1].of.i32;
while (!(n = getline(&addr, &len, stdin))) { *addr = 0;
} fgets(addr, len, stdin);
if (n < 0) { int n = strlen(addr);
n = 0;
}
results->data[0].kind = WASM_I32; results->data[0].kind = WASM_I32;
results->data[0].of.i32 = n; results->data[0].of.i32 = n;
return NULL; return NULL;