One more problem in the same function of libestr. It was unable to process negative numbers correctly. This patch includes previous one.


Is it declared somewhere which integer size rsyslog does support? There is a inconsistence between internal number representation, which is signed long long, and JSON-c integers, which is signed int only. So you can use integers in range -2^63 .. 2^63-1 for RainerScript expressions, but variables can hold no more than -2^31 .. 2^31-1.

set $!min = -2147483648;
set $!max = 2147483647;
set $!under = -2147483648 - 1;
set $!over = 2147483647 + 1;

"min": -2147483648, "max": 2147483647, "under": 2147483647, "over": -2147483648

As a workaround, it is possible to store long numbers as strings:

set $!under_s = cstr(-2147483648 - 1);
set $!over_s = cstr(2147483647 + 1);

"under_s": "-2147483649", "over_s": "2147483648"

But then, they cannot be used in calculations, because are converted to int in json-c:

set $!under_sj = "-1000000000000";
set $!over_sj = "1000000000000";
set $!under_sjn = cstr(cnum($!under_sj));
set $!over_sjn = cstr(cnum($!over_sj));
set $!under_sn = cstr(cnum("-1000000000000"));
set $!over_sn = cstr(cnum("-1000000000000"));

"under_sj": "-1000000000000", "over_sj": "1000000000000", "under_sjn": "-2147483648", "over_sjn": "2147483647", "under_sn": "-1000000000000", "over_sn": "-1000000000000"


--
Pavel Levshin


26.10.2013 3:10, Pavel Levshin ?????:
Hello.

rsyslog fails to convert numbers to strings:

set $.cnt14 = cstr( 123456789 );

{ "cnt14": "13579" }


This is due to a bug in libestr, see patch.


--
Pavel Levshin




_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

>From 879f94af72a6dcb632f3e87904d0cf9494b0ab04 Mon Sep 17 00:00:00 2001
From: Pavel Levshin <[email protected]>
Date: Sat, 26 Oct 2013 12:33:12 +0400
Subject: [PATCH] Bugfixes to StrFromNumber

---
 src/string.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/string.c b/src/string.c
index 3dccd71..483546d 100644
--- a/src/string.c
+++ b/src/string.c
@@ -151,8 +151,14 @@ es_newStrFromNumber(long long num)
 {
        char numbuf[20];        /* 2^64 has 20 digits ;) */
        int i,j;
+       char minus = '\0';
        es_str_t *s;
        
+       if (num < 0) {
+           minus = '-';
+           num = -num;
+       }
+       
        /* generate string (reversed) */
        for(i = 0 ; num != 0 ; ++i) {
                numbuf[i] = num % 10 + '0';
@@ -160,11 +166,13 @@ es_newStrFromNumber(long long num)
        }
        if(i == 0)
                numbuf [i++] = '0';
+       if (minus != '\0')
+               numbuf[i++] = minus;
 
        /* now create the actual string */
        if((s = es_newStr(i)) == NULL) goto done;
        s->lenStr = i;
-       for(j = 0 ; --i >= 0 ; ++j, --i) {
+       for(j = 0 ; --i >= 0 ; ++j) {
                es_getBufAddr(s)[j] = numbuf[i];
        }
 
-- 
1.7.9.5

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to