Fixing truncation handling in SEXP_WRITE_STRING_OP.

This commit is contained in:
Alex Shinn 2012-04-01 18:56:22 +09:00
parent befd0ecfd9
commit 9c0bf42077

20
vm.c
View file

@ -1807,22 +1807,28 @@ sexp sexp_apply (sexp ctx, sexp proc, sexp args) {
if (sexp_port_stream(_ARG3)) {
i = fwrite(sexp_bytes_data(tmp1), 1, sexp_unbox_fixnum(_ARG2), sexp_port_stream(_ARG3));
#if SEXP_USE_GREEN_THREADS
if ((i < sexp_unbox_fixnum(_ARG2)) && ferror(sexp_port_stream(_ARG3))
&& (errno == EAGAIN)
&& sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER))) {
if (i > 0) {
if ((i < sexp_unbox_fixnum(_ARG2))
&& ferror(sexp_port_stream(_ARG3))
&& (errno == EAGAIN)) {
clearerr(sexp_port_stream(_ARG3));
/* modify stack in-place so we continue where we left off next time */
_ARG1 = sexp_substring(ctx, _ARG1, SEXP_ZERO, sexp_make_fixnum(i));
if (i > 0) {
if (sexp_stringp(_ARG1))
_ARG1 = sexp_substring(ctx, _ARG1, sexp_make_fixnum(i), SEXP_FALSE);
else
_ARG1 = sexp_subbytes(ctx, _ARG1, sexp_make_fixnum(i), SEXP_FALSE);
_ARG2 = sexp_make_fixnum(sexp_unbox_fixnum(_ARG2) - i);
}
clearerr(sexp_port_stream(_ARG3));
/* yield if threads are enabled */
if (sexp_applicablep(sexp_global(ctx, SEXP_G_THREADS_BLOCKER))) {
sexp_apply1(ctx, sexp_global(ctx, SEXP_G_THREADS_BLOCKER), _ARG3);
fuel = 0;
}
ip--; /* try again */
goto loop;
}
#endif
} else { /* not a stream-backed string */
} else { /* not a stream-backed string, won't block */
if (sexp_bytes_length(tmp1) != sexp_unbox_fixnum(_ARG2))
tmp1 = sexp_subbytes(ctx, tmp1, SEXP_ZERO, _ARG2);
sexp_write_string(ctx, sexp_bytes_data(tmp1), _ARG3);