Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/db/hash When writing out pages in the "other endian...



details:   https://anonhg.NetBSD.org/src/rev/569bf1eae15a
branches:  trunk
changeset: 347938:569bf1eae15a
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Sep 24 20:08:29 2016 +0000

description:
When writing out pages in the "other endian" format, make a copy instead of
trashing the in-memory one.

diffstat:

 lib/libc/db/hash/hash_page.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (48 lines):

diff -r f7ec2542fe70 -r 569bf1eae15a lib/libc/db/hash/hash_page.c
--- a/lib/libc/db/hash/hash_page.c      Sat Sep 24 15:06:29 2016 +0000
+++ b/lib/libc/db/hash/hash_page.c      Sat Sep 24 20:08:29 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash_page.c,v 1.28 2015/11/18 18:22:42 christos Exp $  */
+/*     $NetBSD: hash_page.c,v 1.29 2016/09/24 20:08:29 christos Exp $  */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hash_page.c,v 1.28 2015/11/18 18:22:42 christos Exp $");
+__RCSID("$NetBSD: hash_page.c,v 1.29 2016/09/24 20:08:29 christos Exp $");
 
 /*
  * PACKAGE:  hashing
@@ -593,6 +593,7 @@
 {
        int fd, page, size;
        ssize_t wsize;
+       char pbuf[MAX_BSIZE];
 
        size = HASH_BSIZE(hashp);
        if ((hashp->fp == -1) && (hashp->fp = __dbtemp("_hash", NULL)) == -1)
@@ -603,15 +604,18 @@
                int i;
                int max;
 
+               memcpy(pbuf, p, size);
                if (is_bitmap) {
                        max = (uint32_t)hashp->BSIZE >> 2;      /* divide by 4 */
                        for (i = 0; i < max; i++)
-                               M_32_SWAP(((int *)(void *)p)[i]);
+                               M_32_SWAP(((int *)(void *)pbuf)[i]);
                } else {
-                       max = ((uint16_t *)(void *)p)[0] + 2;
+                       uint16_t *bp = (uint16_t *)(void *)pbuf;
+                       max = bp[0] + 2;
                        for (i = 0; i <= max; i++)
-                               M_16_SWAP(((uint16_t *)(void *)p)[i]);
+                               M_16_SWAP(bp[i]);
                }
+               p = pbuf;
        }
        if (is_bucket)
                page = BUCKET_TO_PAGE(bucket);



Home | Main Index | Thread Index | Old Index