From 4d4908dde31316462acae5caec8dfcbbf7a244bd Mon Sep 17 00:00:00 2001 From: Alexandre Szymocha Date: Sat, 28 Dec 2019 14:48:36 +0100 Subject: Fix: allow reading into a 0-length array (#3329) --- cli/js/files.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cli/js/files.ts') diff --git a/cli/js/files.ts b/cli/js/files.ts index 66a70f981..d3a4b5809 100644 --- a/cli/js/files.ts +++ b/cli/js/files.ts @@ -50,6 +50,9 @@ export async function open( * */ export function readSync(rid: number, p: Uint8Array): number | EOF { + if (p.length == 0) { + return 0; + } const nread = sendSyncMinimal(dispatch.OP_READ, rid, p); if (nread < 0) { throw new Error("read error"); @@ -70,6 +73,9 @@ export function readSync(rid: number, p: Uint8Array): number | EOF { * const text = new TextDecoder().decode(buf); */ export async function read(rid: number, p: Uint8Array): Promise { + if (p.length == 0) { + return 0; + } const nread = await sendAsyncMinimal(dispatch.OP_READ, rid, p); if (nread < 0) { throw new Error("read error"); -- cgit v1.2.3