X-Git-Url: http://dolda2000.com/gitweb/?p=vcfs.git;a=blobdiff_plain;f=store.c;h=4d4f14f01f79e09226fb4a5dc359a181cb905470;hp=5eef6d84dd26e546f287dbd7710df464d59a097d;hb=487044bbce04292a029b57b04f54b3b9030688fd;hpb=db5f6d168d1cc21e96e7dbefa90df23068ab3e14 diff --git a/store.c b/store.c index 5eef6d8..4d4f14f 100644 --- a/store.c +++ b/store.c @@ -48,13 +48,13 @@ static void cacheput(struct store *st, struct addr *a, const void *data, ssize_t return; if(i < 4) { tmp = st->cache[he * 4 + i]; - memmove(&st->cache[he * 4 + 1], &st->cache[he * 4], i); + memmove(&st->cache[he * 4 + 1], &st->cache[he * 4], i * sizeof(struct storecache)); st->cache[he * 4] = tmp; return; } if(st->cache[he * 4 + 3].data != NULL) free(st->cache[he * 4 + 3].data); - memmove(&st->cache[he * 4 + 1], &st->cache[he * 4], 3); + memmove(&st->cache[he * 4 + 1], &st->cache[he * 4], 3 * sizeof(struct storecache)); st->cache[he * 4].a = *a; if(len > 0) st->cache[he * 4].data = memcpy(malloc(len), data, len); @@ -79,18 +79,20 @@ int storeput(struct store *st, const void *buf, size_t len, struct addr *at) ssize_t storeget(struct store *st, void *buf, size_t len, struct addr *at) { ssize_t sz; + struct addr at2; - sz = cacheget(st, at, buf, len); + at2 = *at; + sz = cacheget(st, at2, buf, len); if(sz != -2) { if(sz == -1) errno = ENOENT; return(sz); } - sz = st->ops->get(st, buf, len, at); + sz = st->ops->get(st, buf, len, at2); if((sz < 0) && (errno == ENOENT)) - cacheput(st, at, NULL, -1); + cacheput(st, at2, NULL, -1); else if(sz >= 0) - cacheput(st, at, buf, sz); + cacheput(st, at2, buf, sz); return(sz); }