Skip to content

Commit 892bddb

Browse files
Release k8-1.0 (r124)
1 parent dbb2d6d commit 892bddb

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Release 1.0-r121 (10 August 2023)
1+
Release 1.0-r124 (10 August 2023)
22
---------------------------------
33

44
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):
4545
* `Bytes.prototype.cast()` - Bytes only supports `uint8_t`
4646
* `Bytes[]` - not possible to implement. Use `Bytes.buffer` as a partial remedy
4747

48-
(1.0: 10 August 2023, r119)
48+
(1.0: 10 August 2023, r124)

k8.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
SOFTWARE.
2525
*/
26-
#define K8_VERSION "1.0-r121"
26+
#define K8_VERSION "1.0-r124"
2727

2828
#include <stdlib.h>
2929
#include <stdint.h>
@@ -358,20 +358,22 @@ static void k8_write_string(FILE *fp, const v8::FunctionCallbackInfo<v8::Value>
358358
v8::HandleScope handle_scope(args.GetIsolate());
359359
if (args[i]->IsString()) {
360360
int64_t len = args[i].As<v8::String>()->Length();
361-
K8_GROW(uint8_t, buf->s, len-1, buf->m);
362-
args[i].As<v8::String>()->WriteOneByte(args.GetIsolate(), buf->s);
363-
fwrite(buf->s, 1, len, fp);
361+
if (len > 0) {
362+
K8_GROW(uint8_t, buf->s, len, buf->m);
363+
args[i].As<v8::String>()->WriteOneByte(args.GetIsolate(), buf->s);
364+
fwrite(buf->s, 1, len, fp);
365+
}
364366
return;
365367
} else if (args[i]->IsArrayBuffer()) {
366368
void *data = args[i].As<v8::ArrayBuffer>()->GetBackingStore()->Data();
367369
int64_t len = args[i].As<v8::ArrayBuffer>()->GetBackingStore()->ByteLength();
368-
fwrite(data, 1, len, fp);
370+
if (len > 0) fwrite(data, 1, len, fp);
369371
return;
370372
} else if (args[i]->IsObject()) {
371373
if (args[i].As<v8::Object>()->InternalFieldCount() > 0) {
372374
k8_bytes_t *a = (k8_bytes_t*)args[i].As<v8::Object>()->GetAlignedPointerFromInternalField(0);
373375
if (a && a->magic == K8_BYTES_MAGIC) {
374-
fwrite(a->buf.s, 1, a->buf.l, fp);
376+
if (a->buf.l > 0) fwrite(a->buf.s, 1, a->buf.l, fp);
375377
return;
376378
}
377379
}
@@ -706,14 +708,14 @@ static void k8_file_write(const v8::FunctionCallbackInfo<v8::Value> &args)
706708
void *data = args[0].As<v8::ArrayBuffer>()->GetBackingStore()->Data();
707709
int64_t len = args[0].As<v8::ArrayBuffer>()->GetBackingStore()->ByteLength();
708710
assert(len >= 0 && len < INT32_MAX);
709-
fwrite(data, 1, len, ks->fpw);
711+
if (len > 0) fwrite(data, 1, len, ks->fpw);
710712
args.GetReturnValue().Set((int32_t)len);
711713
} else if (args[0]->IsString()) {
712714
int32_t len = args[0].As<v8::String>()->Length();
713715
uint8_t *buf;
714716
buf = K8_MALLOC(uint8_t, len);
715717
args[0].As<v8::String>()->WriteOneByte(args.GetIsolate(), buf);
716-
fwrite(buf, 1, len, ks->fpw);
718+
if (len > 0) fwrite(buf, 1, len, ks->fpw);
717719
free(buf);
718720
args.GetReturnValue().Set(len);
719721
}

0 commit comments

Comments
 (0)