mirror of
https://github.com/janet-lang/janet
synced 2025-07-07 20:42:54 +00:00
Don't call fwrite with size = 0
This commit is contained in:
parent
4149df1fca
commit
bb54b940c0
@ -425,8 +425,10 @@ 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 (1 != fwrite(vstr, len, 1, f)) {
|
if (len) {
|
||||||
janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
|
if (1 != fwrite(vstr, len, 1, f)) {
|
||||||
|
janet_panicf("could not print %d bytes to (dyn :%s)", len, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newline)
|
if (newline)
|
||||||
@ -480,8 +482,10 @@ 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 (1 != fwrite(buf->data, buf->count, 1, f)) {
|
if (buf->count) {
|
||||||
janet_panicf("could not print %d bytes to file", buf->count, name);
|
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 */
|
/* Clear buffer to make things easier for GC */
|
||||||
buf->count = 0;
|
buf->count = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user