update ->ptr on rebase, return -1 on failure

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24248 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2009-01-11 21:43:21 +00:00
parent d3cef9ce45
commit 00debe0edd

View File

@@ -67,7 +67,7 @@ emem_store(krb5_storage *sp, const void *data, size_t size)
sz *= 2; sz *= 2;
base = realloc(s->base, sz); base = realloc(s->base, sz);
if(base == NULL) if(base == NULL)
return 0; return -1;
s->size = sz; s->size = sz;
s->base = base; s->base = base;
s->ptr = (unsigned char*)base + off; s->ptr = (unsigned char*)base + off;
@@ -112,8 +112,10 @@ emem_trunc(krb5_storage *sp, off_t offset)
* If offset is larget then current size, or current size is * If offset is larget then current size, or current size is
* shrunk more then half of the current size, adjust buffer. * shrunk more then half of the current size, adjust buffer.
*/ */
if (offset > s->size || s->size / 2 > offset ) { if (offset > s->size || (s->size / 2) > offset) {
void *base; void *base;
size_t off;
off = s->ptr - s->base;
base = realloc(s->base, offset); base = realloc(s->base, offset);
if(base == NULL) if(base == NULL)
return ENOMEM; return ENOMEM;
@@ -121,6 +123,7 @@ emem_trunc(krb5_storage *sp, off_t offset)
memset((char *)base + s->size, 0, offset - s->size); memset((char *)base + s->size, 0, offset - s->size);
s->size = offset; s->size = offset;
s->base = base; s->base = base;
s->ptr = (unsigned char *)base + off;
} }
s->len = offset; s->len = offset;
if ((s->ptr - s->base) > offset) if ((s->ptr - s->base) > offset)