Bug 2545

Summary: Optimized build fails for flow-monitor
Product: ns-3 Reporter: natale.patriciello
Component: flow-monitorAssignee: Tommaso Pecorella <tommaso.pecorella>
Status: RESOLVED FIXED    
Severity: enhancement CC: ns-bugs
Priority: P5    
Version: unspecified   
Hardware: PC   
OS: Linux   
Attachments: patch
slightly different patch

Description natale.patriciello 2016-11-06 06:39:50 UTC
Created attachment 2663 [details]
patch

The problem is the following:

../src/flow-monitor/model/ipv6-flow-classifier.cc: In member function ‘virtual void ns3::Ipv6FlowClassifier::SerializeToXmlStream(std::ostream&, int) const’:
../src/flow-monitor/model/ipv6-flow-classifier.cc:192:51: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
 #define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
                                                    
   INDENT (indent); os << "<Ipv6FlowClassifier>\n";
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 
                                                    
   indent += 2;
   ~~~~~~~~~~~~                                     
   for (std::map<FiveTuple, FlowId>::const_iterator
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
        iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     {
     ~                                              
       INDENT (indent);
       ~~~~~~~~~                                    
../src/flow-monitor/model/ipv6-flow-classifier.cc:200:7: note: in expansion of macro ‘INDENT’
       INDENT (indent);
       ^~~~~~
cc1plus: all warnings being treated as errors

there could be an overflow in level.
The patch fixes the previous by adding a static inline function, that does the same as the macro. Usually, static inline functions are better than macroes, because they do argument type checking.

my gcc version:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 6.2.1 20160830 (GCC)
Comment 1 Tommaso Pecorella 2016-11-08 17:20:38 UTC
Created attachment 2669 [details]
slightly different patch

Hi Nat,

I extended your patch slightly. Can you check if it works for you ?
Comment 2 natale.patriciello 2016-11-11 07:33:37 UTC
It works. For me, you can push as soon as possible. Thank you!
Comment 3 Tommaso Pecorella 2016-11-11 19:05:51 UTC
changeset 12407:bbdde6db40ee