1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Don't call fwrite with size = 0

This commit is contained in:
Calvin Rose 2019-10-19 10:51:11 -05:00
parent 4149df1fca
commit bb54b940c0

View File

@ -425,8 +425,10 @@ static Janet cfun_io_print_impl(int32_t argc, Janet *argv,
vstr = janet_to_string(argv[i]);
len = janet_string_length(vstr);
}
if (1 != fwrite(vstr, len, 1, f)) {
janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
if (len) {
if (1 != fwrite(vstr, len, 1, f)) {
janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
}
}
}
if (newline)
@ -480,8 +482,10 @@ 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 (1 != fwrite(buf->data, buf->count, 1, f)) {
janet_panicf("could not print %d bytes to file", buf->count, name);
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;