1
0
mirror of https://github.com/janet-lang/janet synced 2025-07-07 12:32:55 +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,10 +425,12 @@ static Janet cfun_io_print_impl(int32_t argc, Janet *argv,
vstr = janet_to_string(argv[i]); vstr = janet_to_string(argv[i]);
len = janet_string_length(vstr); len = janet_string_length(vstr);
} }
if (len) {
if (1 != fwrite(vstr, len, 1, f)) { if (1 != fwrite(vstr, len, 1, f)) {
janet_panicf("could not print %d bytes to (dyn :%s)", len, name); janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
} }
} }
}
if (newline) if (newline)
putc('\n', f); putc('\n', f);
return janet_wrap_nil(); return janet_wrap_nil();
@ -480,9 +482,11 @@ static Janet cfun_io_printf_impl(int32_t argc, Janet *argv,
} }
JanetBuffer *buf = janet_buffer(10); JanetBuffer *buf = janet_buffer(10);
janet_buffer_format(buf, fmt, 0, argc, argv); janet_buffer_format(buf, fmt, 0, argc, argv);
if (buf->count) {
if (1 != fwrite(buf->data, buf->count, 1, f)) { if (1 != fwrite(buf->data, buf->count, 1, f)) {
janet_panicf("could not print %d bytes to file", buf->count, name); janet_panicf("could not print %d bytes to file", buf->count, name);
} }
}
/* Clear buffer to make things easier for GC */ /* Clear buffer to make things easier for GC */
buf->count = 0; buf->count = 0;
buf->capacity = 0; buf->capacity = 0;