If you display an object which has a negative small value, and a DISPLAY-HINT 
of something like d-3, then you can get results like:

.0-7

The following patch fixes it, but I think it makes the function a bit of  a 
mess:

diff -Naur net-snmp-5.7.2-unpatched/snmplib/mib.c net-snmp-5.7.2/snmplib/mib.c
--- net-snmp-5.7.2-unpatched/snmplib/mib.c      2013-09-25 14:45:01.516119847 
+0100
+++ net-snmp-5.7.2/snmplib/mib.c        2013-09-25 15:22:16.496347362 +0100
@@ -1223,6 +1223,7 @@
 {
     char            fmt[10] = "%l@", tmp[256];
     int             shift, len;
+    int             signLen = 0;
 
     if (hint[1] == '-') {
         shift = atoi(hint + 2);
@@ -1234,6 +1235,10 @@
         /*
          * We might *actually* want a 'u' here.  
          */
+        if (val < 0) {
+            val = -val;
+            signLen = 1;
+        }
         fmt[2] = decimaltype;
     } else {
         /*
@@ -1257,23 +1262,30 @@
     if (shift != 0) {
         len = strlen(tmp);
         if (shift <= len) {
-            tmp[len + 1] = 0;
+            tmp[len + 1 + signLen] = 0;
             while (shift--) {
-                tmp[len] = tmp[len - 1];
+                tmp[len + signLen] = tmp[len - 1];
                 len--;
             }
-            tmp[len] = '.';
+            tmp[len + signLen] = '.';
+            if (signLen) {
+                while (len--) {
+                    tmp[len + signLen] = tmp[len];
+                }
+                tmp[0] = '-';
+            }
         } else {
-            tmp[shift + 1] = 0;
+            tmp[shift + 1 + signLen] = 0;
             while (shift) {
                 if (len-- > 0) {
-                    tmp[shift] = tmp[len];
+                    tmp[shift + signLen] = tmp[len];
                 } else {
-                    tmp[shift] = '0';
+                    tmp[shift + signLen] = '0';
                 }
                 shift--;
             }
-            tmp[0] = '.';
+            tmp[0] = '-'; /* Will get overwritten on next line for +ve */
+            tmp[signLen] = '.';
         }
     }
     return snmp_strcat(buf, buf_len, out_len, allow_realloc, (u_char *)tmp);
                                          
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to