From 892bddb145a6ec8b95f2c0dc6eff20f76fef63a7 Mon Sep 17 00:00:00 2001 From: Attractive Chaos Date: Thu, 10 Aug 2023 16:34:07 -0400 Subject: [PATCH] Release k8-1.0 (r124) --- NEWS.md | 4 ++-- k8.cc | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index a1d73e9..bbe2834 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -Release 1.0-r121 (10 August 2023) +Release 1.0-r124 (10 August 2023) --------------------------------- The previous version of k8, v0.2.5, was built on top of v8-3.16.4 released on @@ -45,4 +45,4 @@ Removed functions (BREAKING): * `Bytes.prototype.cast()` - Bytes only supports `uint8_t` * `Bytes[]` - not possible to implement. Use `Bytes.buffer` as a partial remedy -(1.0: 10 August 2023, r119) +(1.0: 10 August 2023, r124) diff --git a/k8.cc b/k8.cc index 02deffb..3a309d4 100644 --- a/k8.cc +++ b/k8.cc @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define K8_VERSION "1.0-r121" +#define K8_VERSION "1.0-r124" #include #include @@ -358,20 +358,22 @@ static void k8_write_string(FILE *fp, const v8::FunctionCallbackInfo v8::HandleScope handle_scope(args.GetIsolate()); if (args[i]->IsString()) { int64_t len = args[i].As()->Length(); - K8_GROW(uint8_t, buf->s, len-1, buf->m); - args[i].As()->WriteOneByte(args.GetIsolate(), buf->s); - fwrite(buf->s, 1, len, fp); + if (len > 0) { + K8_GROW(uint8_t, buf->s, len, buf->m); + args[i].As()->WriteOneByte(args.GetIsolate(), buf->s); + fwrite(buf->s, 1, len, fp); + } return; } else if (args[i]->IsArrayBuffer()) { void *data = args[i].As()->GetBackingStore()->Data(); int64_t len = args[i].As()->GetBackingStore()->ByteLength(); - fwrite(data, 1, len, fp); + if (len > 0) fwrite(data, 1, len, fp); return; } else if (args[i]->IsObject()) { if (args[i].As()->InternalFieldCount() > 0) { k8_bytes_t *a = (k8_bytes_t*)args[i].As()->GetAlignedPointerFromInternalField(0); if (a && a->magic == K8_BYTES_MAGIC) { - fwrite(a->buf.s, 1, a->buf.l, fp); + if (a->buf.l > 0) fwrite(a->buf.s, 1, a->buf.l, fp); return; } } @@ -706,14 +708,14 @@ static void k8_file_write(const v8::FunctionCallbackInfo &args) void *data = args[0].As()->GetBackingStore()->Data(); int64_t len = args[0].As()->GetBackingStore()->ByteLength(); assert(len >= 0 && len < INT32_MAX); - fwrite(data, 1, len, ks->fpw); + if (len > 0) fwrite(data, 1, len, ks->fpw); args.GetReturnValue().Set((int32_t)len); } else if (args[0]->IsString()) { int32_t len = args[0].As()->Length(); uint8_t *buf; buf = K8_MALLOC(uint8_t, len); args[0].As()->WriteOneByte(args.GetIsolate(), buf); - fwrite(buf, 1, len, ks->fpw); + if (len > 0) fwrite(buf, 1, len, ks->fpw); free(buf); args.GetReturnValue().Set(len); }