mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Take more care with a NULL reader1 or writer1 buf.
This commit is contained in:
1 parent
10b7d5a031
commit
7b6f7384d1
6 files changed
+28
-21
No files matched your search
@@ -25,11 +25,12 @@ type template_args_short_read struct {
|
||||
}
|
||||
|
||||
func template_short_read(b *buffer, args template_args_short_read) error {
|
||||
b.printf("short_read_%s:\nif (a_%s.limit.ptr_to_len) {\nstatus = %sSUSPENSION_LIMITED_READ;\n} else if (a_%s.buf->closed) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n} else {\nstatus = %sSUSPENSION_SHORT_READ;\n}\ngoto suspend;\n",
|
||||
b.printf("short_read_%s:\nif (a_%s.limit.ptr_to_len) {\nstatus = %sSUSPENSION_LIMITED_READ;\n} else if (a_%s.buf && a_%s.buf->closed) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n} else {\nstatus = %sSUSPENSION_SHORT_READ;\n}\ngoto suspend;\n",
|
||||
args.name,
|
||||
args.name,
|
||||
args.PKGPREFIX,
|
||||
args.name,
|
||||
args.name,
|
||||
args.PKGPREFIX,
|
||||
args.PKGPREFIX,
|
||||
)
|
||||
|
||||
@@ -159,14 +159,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeySlice, 2) {
|
||||
b.printf("puffs_base_make_slice_u8(%sdst.buf->ptr,", aPrefix)
|
||||
b.printf("puffs_base_make_slice_u8(%sdst.buf ? %sdst.buf->ptr : NULL,", aPrefix, aPrefix)
|
||||
for _, o := range n.Args() {
|
||||
if err := g.writeExpr(b, o.Arg().Value(), rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(".ptr,")
|
||||
}
|
||||
b.printf("%swptr_dst)", bPrefix)
|
||||
b.printf("%sdst.buf ? %swptr_dst : NULL)", aPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyLength, 0) {
|
||||
|
||||
@@ -356,7 +356,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
// TODO: is ptr_to_len the right check?
|
||||
b.printf("if (%ssrc.limit.ptr_to_len) {", aPrefix)
|
||||
b.printf("status = %sSUSPENSION_LIMITED_READ;", g.PKGPREFIX)
|
||||
b.printf("} else if (%ssrc.buf->closed) {", aPrefix)
|
||||
b.printf("} else if (%ssrc.buf && %ssrc.buf->closed) {", aPrefix, aPrefix)
|
||||
b.printf("status = %sERROR_UNEXPECTED_EOF; goto exit;", g.PKGPREFIX)
|
||||
b.printf("} else { status = %sSUSPENSION_SHORT_READ; } goto suspend;\n", g.PKGPREFIX)
|
||||
|
||||
@@ -365,7 +365,8 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
|
||||
} else if isInDst(g.tm, n, t.KeyWrite, 1) {
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
b.printf("if (%sdst.buf->closed) { status = %sERROR_CLOSED_FOR_WRITES;", aPrefix, g.PKGPREFIX)
|
||||
b.printf("if (%sdst.buf && %sdst.buf->closed) { status = %sERROR_CLOSED_FOR_WRITES;",
|
||||
aPrefix, aPrefix, g.PKGPREFIX)
|
||||
b.writes("goto exit;")
|
||||
b.writes("}\n")
|
||||
b.printf("if ((%swend_dst - %swptr_dst) < (sizeof(self->private_impl.f_stack) - v_s)) {",
|
||||
@@ -472,6 +473,10 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
const wName = "dst"
|
||||
b.printf("size_t %s%d = (size_t)(%s >> 32);", tPrefix, temp0, scratchName)
|
||||
// TODO: it's not a BAD_ARGUMENT if we can copy from the sliding window.
|
||||
//
|
||||
// TODO: %s%s.buf->ptr might be a NULL pointer dereference. In any
|
||||
// case, we need to compare the (resumed) distance against a mark, not
|
||||
// against the beginning of the dst buffer.
|
||||
b.printf("if (PUFFS_UNLIKELY((%s%d == 0) || (%s%d > (%swptr_%s - %s%s.buf->ptr)))) { "+
|
||||
"status = %sERROR_BAD_ARGUMENT; goto exit; }\n",
|
||||
tPrefix, temp0, tPrefix, temp0, bPrefix, wName, aPrefix, wName, g.PKGPREFIX)
|
||||
|
||||
@@ -12,7 +12,7 @@ short_read_qnameq:
|
||||
// TODO: is ptr_to_len the right check?
|
||||
if (a_qnameq.limit.ptr_to_len) {
|
||||
status = qPKGPREFIXqSUSPENSION_LIMITED_READ;
|
||||
} else if (a_qnameq.buf->closed) {
|
||||
} else if (a_qnameq.buf && a_qnameq.buf->closed) {
|
||||
status = qPKGPREFIXqERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user