[AGENT++] Counter64: in hex - TODO of 2002

Florian Lohoff f at zz.de
Thu Jan 28 17:11:15 CET 2016


Hi,

this is just a quick hack - but getting Counter64 as hex once they
overflow 2^32 is a bit unexpected.

Probably this would need a bit more ifdef spaghetti

#ifdef HAVE_INTTYPES_H
#ifdef PRIu64

something ... But in the ages of c++11 this should all be available.

Flo

diff --git a/src/ctr64.cpp b/src/ctr64.cpp
index 24414ea..2e163c0 100644
--- a/src/ctr64.cpp
+++ b/src/ctr64.cpp
@@ -56,6 +56,7 @@ char counter64_cpp_version[]="@(#) SNMP++ $Id: ctr64.cpp 2361 2013-05-09 22:15:0
 #include "snmp_pp/ctr64.h"
 #include "snmp_pp/asn1.h"
 #include "snmp_pp/v3.h"
+#include <inttypes.h>
 
 #ifdef SNMP_PP_NAMESPACE
 namespace Snmp_pp {
@@ -227,9 +228,6 @@ bool operator>=(const Counter64 &lhs, const Counter64 &rhs)
 #endif
 
 //----------[ return ASCII format ]-------------------------
-// TODO:  Fix up to do real 64bit decimal value printing...
-//        For now, print > 32-bit values in hex
-// 26Nov2002 M.Evstiounin - this method is not thread safe!
 const char *Counter64::get_printable() const
 {
   if (m_changed == false)
@@ -237,10 +235,9 @@ const char *Counter64::get_printable() const
 
   char *buf = PP_CONST_CAST(char*, output_buffer);
   if ( high() != 0 )
-    sprintf(buf, "0x%lX%08lX", high(), low());
+    sprintf(buf, "%" PRIu64, (uint64_t) high()<<32|low());
   else
     sprintf(buf, "%lu", low());
-
   Counter64 *nc_this = PP_CONST_CAST(Counter64*, this);
   nc_this->m_changed = false;
 
-- 
Florian Lohoff                                                 f at zz.de
      We need to self-defend - GnuPG/PGP enable your email today!


More information about the AGENTPP mailing list