Mailing List Archive

broken size_nbr handling
In implementing my own 'human-readable' size parser (would be nice to
have one as a part of one of the usable objects), I noticed there
seemed to be order-of-magnitude issues on the base-10 size definitions
in cfsysline.c. Although the base-2 operations properly increase 2^10
(1024) for each SI prefix, the base-10 ones only increase by one order
of magnitude (10) instead of the proper 10^3 per prefix, ending up
with EB only being 10^8 instead of 10^18.

Following is a simple patch that should put things right:
======================================
diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
index 18643ba..1989247 100644
--- a/runtime/cfsysline.c
+++ b/runtime/cfsysline.c
@@ -215,11 +215,11 @@ static rsRetVal doGetSize(uchar **pp, rsRetVal
(*pSetHdlr)(void*, uid_t), void *
case 'e': i *= (int64) 1024 * 1024 * 1024 * 1024 *
1024 * 1024; ++(*pp); break; /* exa */
/* and now the "new" 1000-based definitions */
case 'K': i *= 1000; ++(*pp); break;
- case 'M': i *= 10000; ++(*pp); break;
- case 'G': i *= 100000; ++(*pp); break;
- case 'T': i *= 1000000; ++(*pp); break; /* tera */
- case 'P': i *= 10000000; ++(*pp); break; /* peta */
- case 'E': i *= 100000000; ++(*pp); break; /* exa */
+ case 'M': i *= 1000000; ++(*pp); break;
+ case 'G': i *= 1000000000; ++(*pp); break;
+ case 'T': i *= 1000000000000; ++(*pp); break; /* tera */
+ case 'P': i *= 1000000000000000; ++(*pp); break; /* peta */
+ case 'E': i *= 1000000000000000000; ++(*pp); break; /* exa */
}

/* done */
======================================
broken size_nbr handling [ In reply to ]
Thanks for spotting this problem and the patch. I have just applied it
to the v3-stable branch, will be moved to all others soon.

Rainer

On Sun, 2008-08-24 at 00:01 -0600, RB wrote:
> In implementing my own 'human-readable' size parser (would be nice to
> have one as a part of one of the usable objects), I noticed there
> seemed to be order-of-magnitude issues on the base-10 size definitions
> in cfsysline.c. Although the base-2 operations properly increase 2^10
> (1024) for each SI prefix, the base-10 ones only increase by one order
> of magnitude (10) instead of the proper 10^3 per prefix, ending up
> with EB only being 10^8 instead of 10^18.
>
> Following is a simple patch that should put things right:
> ======================================
> diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c
> index 18643ba..1989247 100644
> --- a/runtime/cfsysline.c
> +++ b/runtime/cfsysline.c
> @@ -215,11 +215,11 @@ static rsRetVal doGetSize(uchar **pp, rsRetVal
> (*pSetHdlr)(void*, uid_t), void *
> case 'e': i *= (int64) 1024 * 1024 * 1024 * 1024 *
> 1024 * 1024; ++(*pp); break; /* exa */
> /* and now the "new" 1000-based definitions */
> case 'K': i *= 1000; ++(*pp); break;
> - case 'M': i *= 10000; ++(*pp); break;
> - case 'G': i *= 100000; ++(*pp); break;
> - case 'T': i *= 1000000; ++(*pp); break; /* tera */
> - case 'P': i *= 10000000; ++(*pp); break; /* peta */
> - case 'E': i *= 100000000; ++(*pp); break; /* exa */
> + case 'M': i *= 1000000; ++(*pp); break;
> + case 'G': i *= 1000000000; ++(*pp); break;
> + case 'T': i *= 1000000000000; ++(*pp); break; /* tera */
> + case 'P': i *= 1000000000000000; ++(*pp); break; /* peta */
> + case 'E': i *= 1000000000000000000; ++(*pp); break; /* exa */
> }
>
> /* done */
> ======================================
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog