From 33b4ea538521d9583971e31231492736465bea8e Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Wed, 16 Dec 2020 12:13:59 -0800 Subject: [PATCH] Fixed bug with fs.readSync() default values --- microscript/ILibDuktape_fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microscript/ILibDuktape_fs.c b/microscript/ILibDuktape_fs.c index a9885ab..9374350 100644 --- a/microscript/ILibDuktape_fs.c +++ b/microscript/ILibDuktape_fs.c @@ -424,9 +424,9 @@ duk_ret_t ILibDuktape_fs_readSync(duk_context *ctx) duk_size_t bufferSize; char *buffer = Duktape_GetBuffer(ctx, 1, &bufferSize); - int offset = Duktape_GetIntPropertyValue(ctx, 2, "offset", 0); - int length = Duktape_GetIntPropertyValue(ctx, 2, "length", (int)bufferSize); - int position = Duktape_GetIntPropertyValue(ctx, 2, "position", -1); + int offset = narg > 2 ? Duktape_GetIntPropertyValue(ctx, 2, "offset", 0) : 0; + int length = narg > 2 ? Duktape_GetIntPropertyValue(ctx, 2, "length", (int)bufferSize) : (int)bufferSize; + int position = narg > 2 ? Duktape_GetIntPropertyValue(ctx, 2, "position", -1) : -1; int bytesRead; FILE *f = ILibDuktape_fs_getFilePtr(ctx, duk_require_int(ctx, 0));