]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/bupsplit.c
index: fix -H option
[bup.git] / lib / bup / bupsplit.c
index 871e1205b147f7fbb9eee08c9f4ed1d077eff908..d9760f5321d2e9b22673cfafd655ce129aa92cb9 100644 (file)
@@ -1,3 +1,33 @@
+/*
+ * Copyright 2011 Avery Pennarun. All rights reserved.
+ * 
+ * (This license applies to bupsplit.c and bupsplit.h only.)
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *    1. Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ * 
+ *    2. Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY AVERY PENNARUN AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 #include "bupsplit.h"
 #include <stdint.h>
 #include <memory.h>
@@ -76,7 +106,6 @@ int bupsplit_find_ofs(const unsigned char *buf, int len, int *bits)
            if (bits)
            {
                unsigned rsum = rollsum_digest(&r);
-               *bits = BUP_BLOBBITS;
                rsum >>= BUP_BLOBBITS;
                for (*bits = BUP_BLOBBITS; (rsum >>= 1) & 1; (*bits)++)
                    ;
@@ -89,22 +118,23 @@ int bupsplit_find_ofs(const unsigned char *buf, int len, int *bits)
 
 
 #ifndef BUP_NO_SELFTEST
+#define BUP_SELFTEST_SIZE 100000
 
 int bupsplit_selftest()
 {
-    uint8_t buf[100000];
+    uint8_t *buf = malloc(BUP_SELFTEST_SIZE);
     uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b;
     unsigned count;
     
     srandom(1);
-    for (count = 0; count < sizeof(buf); count++)
+    for (count = 0; count < BUP_SELFTEST_SIZE; count++)
        buf[count] = random();
     
-    sum1a = rollsum_sum(buf, 0, sizeof(buf));
-    sum1b = rollsum_sum(buf, 1, sizeof(buf));
-    sum2a = rollsum_sum(buf, sizeof(buf) - BUP_WINDOWSIZE*5/2,
-                       sizeof(buf) - BUP_WINDOWSIZE);
-    sum2b = rollsum_sum(buf, 0, sizeof(buf) - BUP_WINDOWSIZE);
+    sum1a = rollsum_sum(buf, 0, BUP_SELFTEST_SIZE);
+    sum1b = rollsum_sum(buf, 1, BUP_SELFTEST_SIZE);
+    sum2a = rollsum_sum(buf, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE*5/2,
+                       BUP_SELFTEST_SIZE - BUP_WINDOWSIZE);
+    sum2b = rollsum_sum(buf, 0, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE);
     sum3a = rollsum_sum(buf, 0, BUP_WINDOWSIZE+3);
     sum3b = rollsum_sum(buf, 3, BUP_WINDOWSIZE+3);
     
@@ -115,6 +145,7 @@ int bupsplit_selftest()
     fprintf(stderr, "sum3a = 0x%08x\n", sum3a);
     fprintf(stderr, "sum3b = 0x%08x\n", sum3b);
     
+    free(buf);
     return sum1a!=sum1b || sum2a!=sum2b || sum3a!=sum3b;
 }