]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix bsnprintf for float point numbers. I broke recently when
authorKern Sibbald <kern@sibbald.com>
Tue, 8 Jan 2008 16:11:06 +0000 (16:11 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 8 Jan 2008 16:11:06 +0000 (16:11 +0000)
     parameterizing some variables.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.2@6258 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/patches/2.2.7-fpformat.patch [new file with mode: 0644]
bacula/src/lib/bsnprintf.c
bacula/technotes-2.1

diff --git a/bacula/patches/2.2.7-fpformat.patch b/bacula/patches/2.2.7-fpformat.patch
new file mode 100644 (file)
index 0000000..c022627
--- /dev/null
@@ -0,0 +1,120 @@
+
+ This patch fixes a float point editing bug introduced in 2.2.7 (I think)
+ causing the rate fields to be formated incorrectly (actually trunctated).
+ This fixes bug #1036.
+
+ Apply it to version 2.2.7 with:
+
+ cd <bacula-source>
+ patch -p0 <2.2.7-fpformat.patch
+ ./configure <your-options>
+ make
+ ...
+ make install
+
+
+Index: src/lib/bsnprintf.c
+===================================================================
+--- src/lib/bsnprintf.c        (revision 6183)
++++ src/lib/bsnprintf.c        (working copy)
+@@ -16,7 +16,7 @@
+ /*
+    Bacula® - The Network Backup Solution
+-   Copyright (C) 2005-2007 Free Software Foundation Europe e.V.
++   Copyright (C) 2005-2008 Free Software Foundation Europe e.V.
+    The main author of Bacula is Kern Sibbald, with contributions from
+    many others, a complete list can be found in the file AUTHORS.
+@@ -566,11 +566,11 @@
+    return result;
+ }
+-static long round(LDOUBLE value)
++static int64_t round(LDOUBLE value)
+ {
+-   long intpart;
++   int64_t intpart;
+-   intpart = (long)value;
++   intpart = (int64_t)value;
+    value = value - intpart;
+    if (value >= 0.5)
+       intpart++;
+@@ -584,8 +584,8 @@
+    int signvalue = 0;
+    LDOUBLE ufvalue;
+ #ifndef HAVE_FCVT
+-   char iconvert[25];
+-   char fconvert[25];
++   char iconvert[311];
++   char fconvert[311];
+ #else
+    char iconvert[311];
+    char fconvert[311];
+@@ -602,6 +602,7 @@
+    int caps = 0;
+    int64_t intpart;
+    int64_t fracpart;
++   const char *cvt_str;
+    /* 
+     * AIX manpage says the default is 0, but Solaris says the default
+@@ -625,7 +626,7 @@
+ #endif
+ #ifndef HAVE_FCVT
+-   intpart = (long)ufvalue;
++   intpart = (int64_t)ufvalue;
+    /* 
+     * Sorry, we only support 9 digits past the decimal because of our 
+@@ -645,28 +646,30 @@
+    }
+ #ifdef DEBUG_SNPRINTF
+-   printf("fmtfp: %g %d.%d min=%d max=%d\n",
++   printf("fmtfp: %g %lld.%lld min=%d max=%d\n",
+           (double)fvalue, intpart, fracpart, min, max);
+ #endif
+    /* Convert integer part */
++   cvt_str = caps ? "0123456789ABCDEF" : "0123456789abcdef";
+    do {
+-      iconvert[iplace++] =
+-         (caps ? "0123456789ABCDEF" : "0123456789abcdef")[intpart % 10];
++      iconvert[iplace++] = cvt_str[(int)(intpart % 10)];
+       intpart = (intpart / 10);
+-   } while (intpart && (iplace < (int)sizeof(iplace)));
+-   if (iplace == (int)sizeof(iplace)) {
++   } while (intpart && (iplace < (int)sizeof(iconvert)));
++
++   if (iplace == (int)sizeof(fconvert)) {
+       iplace--;
+    }
+    iconvert[iplace] = 0;
+    /* Convert fractional part */
++   cvt_str = caps ? "0123456789ABCDEF" : "0123456789abcdef";
+    do {
+-      fconvert[fplace++] =
+-         (caps ? "0123456789ABCDEF" : "0123456789abcdef")[fracpart % 10];
++      fconvert[fplace++] = cvt_str[fracpart % 10];
+       fracpart = (fracpart / 10);
+-   } while (fracpart && (fplace < (int)sizeof(fplace)));
+-   if (fplace == (int)sizeof(fplace)) {
++   } while (fracpart && (fplace < (int)sizeof(fconvert)));
++
++   if (fplace == (int)sizeof(fconvert)) {
+       fplace--;
+    }
+    fconvert[fplace] = 0;
+@@ -825,7 +828,7 @@
+       NULL
+    };
+    double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
+-      0.9996, 1.996, 4.136, 6442452944.1234, 0
++      0.9996, 1.996, 4.136, 6442452944.1234, 0, 23365.5
+    };
+ #endif
+    char *int_fmt[] = {
index 4800c3e60acab85193863ef79b8a3896fe1c8919..cbb6966ce51a3d306b9f8954653153d25eae22be 100644 (file)
@@ -16,7 +16,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2005-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2005-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -566,11 +566,11 @@ static LDOUBLE pow10(int exp)
    return result;
 }
 
-static long round(LDOUBLE value)
+static int64_t round(LDOUBLE value)
 {
-   long intpart;
+   int64_t intpart;
 
-   intpart = (long)value;
+   intpart = (int64_t)value;
    value = value - intpart;
    if (value >= 0.5)
       intpart++;
@@ -584,8 +584,8 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
    int signvalue = 0;
    LDOUBLE ufvalue;
 #ifndef HAVE_FCVT
-   char iconvert[25];
-   char fconvert[25];
+   char iconvert[311];
+   char fconvert[311];
 #else
    char iconvert[311];
    char fconvert[311];
@@ -602,6 +602,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
    int caps = 0;
    int64_t intpart;
    int64_t fracpart;
+   const char *cvt_str;
 
    /* 
     * AIX manpage says the default is 0, but Solaris says the default
@@ -625,7 +626,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 #endif
 
 #ifndef HAVE_FCVT
-   intpart = (long)ufvalue;
+   intpart = (int64_t)ufvalue;
 
    /* 
     * Sorry, we only support 9 digits past the decimal because of our 
@@ -645,28 +646,30 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
    }
 
 #ifdef DEBUG_SNPRINTF
-   printf("fmtfp: %g %d.%d min=%d max=%d\n",
+   printf("fmtfp: %g %lld.%lld min=%d max=%d\n",
           (double)fvalue, intpart, fracpart, min, max);
 #endif
 
    /* Convert integer part */
+   cvt_str = caps ? "0123456789ABCDEF" : "0123456789abcdef";
    do {
-      iconvert[iplace++] =
-         (caps ? "0123456789ABCDEF" : "0123456789abcdef")[intpart % 10];
+      iconvert[iplace++] = cvt_str[(int)(intpart % 10)];
       intpart = (intpart / 10);
-   } while (intpart && (iplace < (int)sizeof(iplace)));
-   if (iplace == (int)sizeof(iplace)) {
+   } while (intpart && (iplace < (int)sizeof(iconvert)));
+
+   if (iplace == (int)sizeof(fconvert)) {
       iplace--;
    }
    iconvert[iplace] = 0;
 
    /* Convert fractional part */
+   cvt_str = caps ? "0123456789ABCDEF" : "0123456789abcdef";
    do {
-      fconvert[fplace++] =
-         (caps ? "0123456789ABCDEF" : "0123456789abcdef")[fracpart % 10];
+      fconvert[fplace++] = cvt_str[fracpart % 10];
       fracpart = (fracpart / 10);
-   } while (fracpart && (fplace < (int)sizeof(fplace)));
-   if (fplace == (int)sizeof(fplace)) {
+   } while (fracpart && (fplace < (int)sizeof(fconvert)));
+
+   if (fplace == (int)sizeof(fconvert)) {
       fplace--;
    }
    fconvert[fplace] = 0;
@@ -825,7 +828,7 @@ int main(void)
       NULL
    };
    double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
-      0.9996, 1.996, 4.136, 6442452944.1234, 0
+      0.9996, 1.996, 4.136, 6442452944.1234, 0, 23365.5
    };
 #endif
    char *int_fmt[] = {
index 828f06c42dbb2e56b978bad262f3f74b1d26881e..d18efb836ef95d5a773f5a17a7f4f9971e05e178 100644 (file)
@@ -1,6 +1,9 @@
               Technical notes on version 2.2
 
 General:
+08Jan08
+kes  Fix bsnprintf for float point numbers. I broke recently when
+     parameterizing some variables.
 03Jan08
 kes  Move Heartbeat documentation from Job to Director resource.
      This fixes bug #1033.