Changeset: 58c42c2e2250 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=58c42c2e2250
Modified Files:
        gdk/gdk_bbp.c
Branch: Mar2018
Log Message:

Use unsigned integers to read BBP.dir.


diffs (214 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1078,22 +1078,24 @@ static int
 headheapinit(oid *hseq, const char *buf, bat bid)
 {
        char type[11];
-       unsigned short width;
-       unsigned short var;
-       unsigned short properties;
-       lng nokey0;
-       lng nokey1;
-       lng nosorted;
-       lng norevsorted;
-       lng base;
-       lng align;
-       lng free;
-       lng size;
-       unsigned short storage;
+       uint16_t width;
+       uint16_t var;
+       uint16_t properties;
+       uint64_t nokey0;
+       uint64_t nokey1;
+       uint64_t nosorted;
+       uint64_t norevsorted;
+       uint64_t base;
+       uint64_t align;
+       uint64_t free;
+       uint64_t size;
+       uint16_t storage;
        int n;
 
        if (sscanf(buf,
-                  " %10s %hu %hu %hu "LLFMT" "LLFMT" "LLFMT" "LLFMT" "LLFMT" 
"LLFMT" "LLFMT" "LLFMT" %hu"
+                  " %10s %" SCNu16 " %" SCNu16 " %" SCNu16 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu16
                   "%n",
                   type, &width, &var, &properties, &nokey0,
                   &nokey1, &nosorted, &norevsorted, &base,
@@ -1103,11 +1105,7 @@ headheapinit(oid *hseq, const char *buf,
 
        if (strcmp(type, "void") != 0)
                GDKfatal("BBPinit: head column must be VOID (ID = %d).", (int) 
bid);
-       if (base < 0
-#if SIZEOF_OID < SIZEOF_LNG
-           || base > (lng) GDK_oid_max
-#endif
-               )
+       if (base > (uint64_t) GDK_oid_max)
                GDKfatal("BBPinit: head seqbase out of range (ID = %d, seq = 
"LLFMT").", (int) bid, base);
        *hseq = (oid) base;
        return n;
@@ -1118,18 +1116,18 @@ heapinit(BAT *b, const char *buf, int *h
 {
        int t;
        char type[11];
-       unsigned short width;
-       unsigned short var;
-       unsigned short properties;
-       lng nokey0;
-       lng nokey1;
-       lng nosorted;
-       lng norevsorted;
-       lng base;
-       lng align;
-       lng free;
-       lng size;
-       unsigned short storage;
+       uint16_t width;
+       uint16_t var;
+       uint16_t properties;
+       uint64_t nokey0;
+       uint64_t nokey1;
+       uint64_t nosorted;
+       uint64_t norevsorted;
+       uint64_t base;
+       uint64_t align;
+       uint64_t free;
+       uint64_t size;
+       uint16_t storage;
        int n;
 
        (void) bbpversion;      /* could be used to implement compatibility */
@@ -1137,14 +1135,18 @@ heapinit(BAT *b, const char *buf, int *h
        norevsorted = 0; /* default for first case */
        if (bbpversion <= GDKLIBRARY_TALIGN ?
            sscanf(buf,
-                  " %10s %hu %hu %hu "LLFMT" "LLFMT" "LLFMT" "LLFMT" "LLFMT" 
"LLFMT" "LLFMT" "LLFMT" %hu"
+                  " %10s %" SCNu16 " %" SCNu16 " %" SCNu16 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu16
                   "%n",
                   type, &width, &var, &properties, &nokey0,
                   &nokey1, &nosorted, &norevsorted, &base,
                   &align, &free, &size, &storage,
                   &n) < 13 :
                sscanf(buf,
-                  " %10s %hu %hu %hu "LLFMT" "LLFMT" "LLFMT" "LLFMT" "LLFMT" 
"LLFMT" "LLFMT" %hu"
+                  " %10s %" SCNu16 " %" SCNu16 " %" SCNu16 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+                  " %" SCNu64 " %" SCNu64 " %" SCNu16
                   "%n",
                   type, &width, &var, &properties, &nokey0,
                   &nokey1, &nosorted, &norevsorted, &base,
@@ -1189,7 +1191,7 @@ heapinit(BAT *b, const char *buf, int *h
        b->tnil = (properties & 0x0800) != 0;
        b->tnosorted = (BUN) nosorted;
        b->tnorevsorted = (BUN) norevsorted;
-       b->tseqbase = base < 0 ? oid_nil : (oid) base;
+       b->tseqbase = base >= (uint64_t) oid_nil ? oid_nil : (oid) base;
        b->theap.free = (size_t) free;
        b->theap.size = (size_t) size;
        b->theap.base = NULL;
@@ -1209,15 +1211,15 @@ static int
 vheapinit(BAT *b, const char *buf, int hashash, bat bid, const char *filename)
 {
        int n = 0;
-       lng free, size;
-       unsigned short storage;
+       uint64_t free, size;
+       uint16_t storage;
 
        if (b->tvarsized && b->ttype != TYPE_void) {
                b->tvheap = GDKzalloc(sizeof(Heap));
                if (b->tvheap == NULL)
                        GDKfatal("BBPinit: cannot allocate memory for heap.");
                if (sscanf(buf,
-                          " "LLFMT" "LLFMT" %hu"
+                          " %" SCNu64 " %" SCNu64 " %" SCNu16
                           "%n",
                           &free, &size, &storage, &n) < 3)
                        GDKfatal("BBPinit: invalid format for BBP.dir\n%s", 
buf);
@@ -1249,8 +1251,8 @@ BBPreadEntries(FILE *fp, unsigned bbpver
 
        /* read the BBP.dir and insert the BATs into the BBP */
        while (fgets(buf, sizeof(buf), fp) != NULL) {
-               lng batid;
-               unsigned short status;
+               uint64_t batid;
+               uint16_t status;
                char headname[129];
                char filename[24];
                unsigned int properties;
@@ -1258,11 +1260,11 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                int nread;
                char *s, *options = NULL;
                char logical[1024];
-               lng inserted = 0, deleted = 0, first = 0, count, capacity, base 
= 0;
+               uint64_t inserted = 0, deleted = 0, first = 0, count, capacity, 
base = 0;
 #ifdef GDKLIBRARY_HEADED
                /* these variables are not used in later versions */
                char tailname[129];
-               unsigned short map_head = 0, map_tail = 0, map_hheap = 0, 
map_theap = 0;
+               uint16_t map_head = 0, map_tail = 0, map_hheap = 0, map_theap = 
0;
 #endif
                int Thashash;
 
@@ -1276,7 +1278,10 @@ BBPreadEntries(FILE *fp, unsigned bbpver
 
                if (bbpversion <= GDKLIBRARY_INSERTED ?
                    sscanf(buf,
-                          LLFMT" %hu %128s %128s %23s %d %u "LLFMT" "LLFMT" 
"LLFMT" "LLFMT" "LLFMT" %hu %hu %hu %hu"
+                          "%" SCNu64 " %" SCNu16 " %128s %128s %23s %d %u"
+                          " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64
+                          " %" SCNu64 " %" SCNu16 " %" SCNu16 " %" SCNu16
+                          " %" SCNu16 ""
                           "%n",
                           &batid, &status, headname, tailname, filename,
                           &lastused, &properties, &inserted, &deleted, &first,
@@ -1285,7 +1290,9 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                           &nread) < 16 :
                    bbpversion <= GDKLIBRARY_HEADED ?
                    sscanf(buf,
-                          LLFMT" %hu %128s %128s %23s %d %u "LLFMT" "LLFMT" 
"LLFMT" %hu %hu %hu %hu"
+                          "%" SCNu64 " %" SCNu16 " %128s %128s %23s %d %u"
+                          " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu16
+                          " %" SCNu16 " %" SCNu16 " %" SCNu16
                           "%n",
                           &batid, &status, headname, tailname, filename,
                           &lastused, &properties, &first,
@@ -1293,7 +1300,8 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                           &map_theap,
                           &nread) < 14 :
                    sscanf(buf,
-                          LLFMT" %hu %128s %23s %u "LLFMT" "LLFMT" "LLFMT
+                          "%" SCNu64 " %" SCNu16 " %128s %23s %u %" SCNu64
+                          " %" SCNu64 " %" SCNu64
                           "%n",
                           &batid, &status, headname, filename,
                           &properties,
@@ -1320,7 +1328,7 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                        GDKfatal("BBPinit: first != 0 (ID = "LLFMT").", batid);
 
                bid = (bat) batid;
-               if (batid >= (lng) ATOMIC_GET(BBPsize, BBPsizeLock)) {
+               if (batid >= (uint64_t) ATOMIC_GET(BBPsize, BBPsizeLock)) {
                        ATOMIC_SET(BBPsize, (ATOMIC_TYPE) (batid + 1), 
BBPsizeLock);
                        if ((bat) ATOMIC_GET(BBPsize, BBPsizeLock) >= BBPlimit)
                                BBPextend(0, false);
@@ -1343,11 +1351,7 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                if (bbpversion <= GDKLIBRARY_HEADED) {
                        nread += headheapinit(&bn->hseqbase, buf + nread, bid);
                } else {
-                       if (base < 0
-#if SIZEOF_OID < SIZEOF_LNG
-                           || base > (lng) GDK_oid_max
-#endif
-                               )
+                       if (base > (uint64_t) GDK_oid_max)
                                GDKfatal("BBPinit: head seqbase out of range 
(ID = "LLFMT", seq = "LLFMT").", batid, base);
                        bn->hseqbase = (oid) base;
                }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to