Patch from Mats Palmgren for bug 424558 (r=me).

This commit is contained in:
Brendan Eich 2010-03-14 16:12:47 -05:00
parent e0c72a18bd
commit 9718113bc4

View File

@ -555,13 +555,18 @@ SprintEnsureBuffer(Sprinter *sp, size_t len)
static ptrdiff_t static ptrdiff_t
SprintPut(Sprinter *sp, const char *s, size_t len) SprintPut(Sprinter *sp, const char *s, size_t len)
{ {
ptrdiff_t offset; ptrdiff_t offset = sp->size; /* save old size */
char *bp; char *bp = sp->base; /* save old base */
/* Allocate space for s, including the '\0' at the end. */ /* Allocate space for s, including the '\0' at the end. */
if (!SprintEnsureBuffer(sp, len)) if (!SprintEnsureBuffer(sp, len))
return -1; return -1;
if (sp->base != bp && /* buffer was realloc'ed */
s >= bp && s < bp + offset) { /* s was within the buffer */
s = sp->base + (s - bp); /* this is where it lives now */
}
/* Advance offset and copy s into sp's buffer. */ /* Advance offset and copy s into sp's buffer. */
offset = sp->offset; offset = sp->offset;
sp->offset += len; sp->offset += len;