mirror of
https://github.com/remko/waforth
synced 2024-12-26 09:59:09 +01:00
standalone: Use fgets() instead of getline() for reading
getline() is incorrect (it can reallocate)
This commit is contained in:
parent
371ab4c6a7
commit
e7a45f5b0c
2 changed files with 4 additions and 7 deletions
2
.github/workflows/publish-standalone.yml
vendored
2
.github/workflows/publish-standalone.yml
vendored
|
@ -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)" \
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue