Don't call fwrite with size = 0
@@ -425,10 +425,12 @@ static Janet cfun_io_print_impl(int32_t argc, Janet *argv,
vstr = janet_to_string(argv[i]);
len = janet_string_length(vstr);
}
+ if (len) {
if (1 != fwrite(vstr, len, 1, f)) {
janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
}
}
+ }
if (newline)
putc('\n', f);
return janet_wrap_nil();
@@ -480,9 +482,11 @@ static Janet cfun_io_printf_impl(int32_t argc, Janet *argv,
}
JanetBuffer *buf = janet_buffer(10);
janet_buffer_format(buf, fmt, 0, argc, argv);
+ if (buf->count) {
if (1 != fwrite(buf->data, buf->count, 1, f)) {
janet_panicf("could not print %d bytes to file", buf->count, name);
}
+ }
/* Clear buffer to make things easier for GC */
buf->count = 0;
buf->capacity = 0;
