26.10.2013 19:35, Pavel Levshin:

26.10.2013 19:14, Rainer Gerhards:

It will still fail to display -LLONG_MAX, btw.
you actually mean -LLONG_MAX or LLONG_MIN? -LLONG_MAX is off the long long
range...


Yep, I've got it wrong. -LLONG_MAX is not off the range, though, it will be displayed properly.

LLONG_MIN will be displayed in a wrong way, because -LLONG_MIN is off the range and will overflow to LLONG_MIN again.

It's up to you to deside, it is not of a big value, of course.


Or maybe this is more generic.


--
Pavel

>From 501d09b87fe269e07d93ed5b15980ab73c4ffae5 Mon Sep 17 00:00:00 2001
From: Pavel Levshin <[email protected]>
Date: Sat, 26 Oct 2013 19:43:36 +0400
Subject: [PATCH] Display LLONG_MIN properly

---
 src/string.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/string.c b/src/string.c
index 483546d..0498025 100644
--- a/src/string.c
+++ b/src/string.c
@@ -151,23 +151,22 @@ es_newStrFromNumber(long long num)
 {
        char numbuf[20];        /* 2^64 has 20 digits ;) */
        int i,j;
-       char minus = '\0';
+       short sign = 1;
        es_str_t *s;
        
        if (num < 0) {
-           minus = '-';
-           num = -num;
+           sign = -1;
        }
        
        /* generate string (reversed) */
        for(i = 0 ; num != 0 ; ++i) {
-               numbuf[i] = num % 10 + '0';
+               numbuf[i] = (num % 10) * sign + '0';
                num /= 10;
        }
        if(i == 0)
                numbuf [i++] = '0';
-       if (minus != '\0')
-               numbuf[i++] = minus;
+       if (sign == -1)
+               numbuf[i++] = '-';
 
        /* now create the actual string */
        if((s = es_newStr(i)) == NULL) goto done;
-- 
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