1) made faNextOffset(), faFirstOffset() return signed ints
authorewt <devnull@localhost>
Wed, 29 Jan 1997 17:39:11 +0000 (17:39 +0000)
committerewt <devnull@localhost>
Wed, 29 Jan 1997 17:39:11 +0000 (17:39 +0000)
2) both return -1 on error
3) faNextOffset() detects loops and returns -1

CVS patchset: 1374
CVS date: 1997/01/29 17:39:11

lib/falloc.c
lib/falloc.h

index 7247a05..908f32c 100644 (file)
@@ -384,11 +384,11 @@ void faClose(faFile fa) {
     free(fa);
 }
 
-unsigned int faFirstOffset(faFile fa) {
+int faFirstOffset(faFile fa) {
     return faNextOffset(fa, 0);
 }
 
-unsigned int faNextOffset(faFile fa, unsigned int lastOffset) {
+int faNextOffset(faFile fa, unsigned int lastOffset) {
     struct faHeader header;
     int offset;
 
@@ -417,8 +417,13 @@ unsigned int faNextOffset(faFile fa, unsigned int lastOffset) {
        if (!header.isFree) break;
     } while (offset < fa->fileSize && header.isFree);
 
-    if (offset < fa->fileSize)
-       return (offset + sizeof(header));
-    else
+    if (offset < fa->fileSize) {
+       /* Sanity check this to make sure we're not going in loops */
+       offset += sizeof(header);
+
+       if (offset <= lastOffset) return -1;
+
+       return offset;
+    } else
        return 0;
 }
index 49c2add..3b710f2 100644 (file)
@@ -21,7 +21,7 @@ unsigned int faAlloc(faFile fa, unsigned int size); /* returns 0 on failure */
 void faFree(faFile fa, unsigned int offset);
 void faClose(faFile fa);
 
-unsigned int faFirstOffset(faFile fa);
-unsigned int faNextOffset(faFile fa, unsigned int lastOffset);  /* 0 at end */
+int faFirstOffset(faFile fa);
+int faNextOffset(faFile fa, unsigned int lastOffset);  /* 0 at end */
 
 #endif H_FALLOC