Hello,
2013/2/7 Radosław Korzeniewski <rados...@korzeniewski.net>
> Hello,
>
> 2013/2/7 Eric Bollengier <eric.bolleng...@baculasystems.com>
>
>> Hello Radosław,
>>
>> On 02/07/2013 05:42 PM, Radosław Korzeniewski wrote:
>> >
>> > I have a question regarding a Bacula bsnprintf library function. Is
>> > bsnprintf supposed to work with a format: "%.2f"? If so, I found a
>> > strange behavior or a bug.
>>
>> bsnprintf is a "partial" implementation of the snprintf function, the
>> main goal is to be portable between all systems, and the second goal,
>> not least, is to not expose Bacula to security issues due to special %
>> formats (some of them can execute code in the stack for example, very
>> powerful, but not used 99% of the time and very dangerous).
>>
>
> I know that, I read the code :)
>
>
>>
>> Bacula is not currently using floating numbers, so the %f implementation
>> is not implemented.
>>
>>
> Not exactly true, bsnprintf has a %f implementation and it is used at
> least in software compression ratio messages at the end of every job (see
> around: src/dird/backup.c:726).
>
> Additionally, If you test other floating point numbers bsnprintf library
> function works. The only problem (bug) I found is proper generation of
> numbers in range of 1.01 till 1.09.
>
> The main difference between compression ratio messages usage and my
> requirement is a fractional number precision - 1 digit vs. 2 digits. But
> according to src/lib/bsnprintf.c:693, it should support up to 9 digits:
>
> /*
> * Sorry, we only support 9 digits past the decimal because of our
> * conversion method
> */
>
> So, in my very humble opinion it should work but it doesn't. Or do I miss
> something?
>
>
I check a code deeper and below is my patch which fix %f conversion in
bsnprintf.
diff --git a/bacula/src/lib/bsnprintf.c b/bacula/src/lib/bsnprintf.c
index afef57c..726bab6 100644
--- a/bacula/src/lib/bsnprintf.c
+++ b/bacula/src/lib/bsnprintf.c
@@ -726,10 +726,11 @@ static int32_t fmtfp(char *buffer, int32_t currlen,
int32_t maxlen,
/* Convert fractional part */
cvt_str = caps ? "0123456789ABCDEF" : "0123456789abcdef";
+ int fiter = max;
do {
fconvert[fplace++] = cvt_str[fracpart % 10];
fracpart = (fracpart / 10);
- } while (fracpart && (fplace < (int)sizeof(fconvert)));
+ } while (--fiter);
if (fplace == (int)sizeof(fconvert)) {
fplace--;
BTW. I wonder why cvt_str points to string which contains hex digits when
we use base 10 in floating point conversion?
best regards
--
Radosław Korzeniewski
rados...@korzeniewski.net
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Bacula-devel mailing list
Bacula-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-devel