043ed5add3d6a0d24037a85b53b43ac9e14211c6
braney
  Sat Aug 17 13:06:42 2024 -0700
fix a couple of bugs when reduction level sizes have the 31st bit set.

diff --git src/lib/bbiRead.c src/lib/bbiRead.c
index f1ae799..f5c6277 100644
--- src/lib/bbiRead.c
+++ src/lib/bbiRead.c
@@ -11,43 +11,49 @@
 #include "zlibFace.h"
 #include "bPlusTree.h"
 #include "hmmstats.h"
 #include "cirTree.h"
 #include "udc.h"
 #include "bbiFile.h"
 
 struct bbiZoomLevel *bbiBestZoom(struct bbiZoomLevel *levelList, int desiredReduction)
 /* Return zoom level that is the closest one that is less than or equal to 
  * desiredReduction. */
 {
 if (desiredReduction < 0)
    errAbort("bad value %d for desiredReduction in bbiBestZoom", desiredReduction);
 if (desiredReduction <= 1)
     return NULL;
-int closestDiff = BIGNUM;
+unsigned closestDiff = ~0;
 struct bbiZoomLevel *closestLevel = NULL;
 struct bbiZoomLevel *level;
 
 for (level = levelList; level != NULL; level = level->next)
     {
-    int diff = desiredReduction - level->reductionLevel;
-    if (diff >= 0 && diff < closestDiff)
+    if (desiredReduction > level->reductionLevel)
+        {
+        // I think we could just break here since levels
+        // are sorted in increasing order, but.. maybe they
+        // aren't always, so let's go ahead and look at the other levels
+        unsigned diff = desiredReduction - level->reductionLevel;
+        if (diff < closestDiff)
             {
             closestDiff = diff;
             closestLevel = level;
             }
 	}
+    }
 return closestLevel;
 }
 
 boolean bbiFileCheckSigs(char *fileName, bits32 sig, char *typeName)
 /* check file signatures at beginning and end of file */
 {
 int fd = mustOpenFd(fileName, O_RDONLY);
 bits32 magic;
 boolean isSwapped = FALSE;
 
 // look for signature at the beginning of the file
 mustReadFd(fd, &magic, sizeof(magic));
 
 if (magic != sig)
     {