From e7a45f5b0c2e322c4fca53e4cbab6aa4c7b8c25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sat, 8 Oct 2022 08:36:26 +0200 Subject: [PATCH] standalone: Use fgets() instead of getline() for reading getline() is incorrect (it can reallocate) --- .github/workflows/publish-standalone.yml | 2 +- src/standalone/main.c | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-standalone.yml b/.github/workflows/publish-standalone.yml index e7b6a52..8fae413 100644 --- a/.github/workflows/publish-standalone.yml +++ b/.github/workflows/publish-standalone.yml @@ -21,7 +21,7 @@ jobs: - run: make -C src/standalone check - name: "Upload artifacts" 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 \ -H "Authorization: token $GITHUB_TOKEN" \ -H "Content-Type: $(file -b --mime-type $f)" \ diff --git a/src/standalone/main.c b/src/standalone/main.c index 9194b88..ab24b01 100644 --- a/src/standalone/main.c +++ b/src/standalone/main.c @@ -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) { - int n = 0; char *addr = &wasm_memory_data(memory)[args->data[0].of.i32]; size_t len = args->data[1].of.i32; - while (!(n = getline(&addr, &len, stdin))) { - } - if (n < 0) { - n = 0; - } + *addr = 0; + fgets(addr, len, stdin); + int n = strlen(addr); results->data[0].kind = WASM_I32; results->data[0].of.i32 = n; return NULL;