build: Enabling -Werror in debug mode and fixing discovered issues

Change-Id: I29685dcb9240a3e0c8d7eaf28c8bc2ae720e55a1
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 96d1ce7..4028ad5 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -317,6 +317,9 @@
           try
             {
               keepAliveInterval = i->second.get_value<size_t>();
+
+              /// \todo Make use of keepAliveInterval
+              (void)(keepAliveInterval);
             }
           catch (const std::exception& e)
             {
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index 0e0bb6a..bad684e 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -138,21 +138,19 @@
 
   NFD_LOG_DEBUG("Not a duplicate");
 
-  int randomLayer = pickRandomLayer();
+  size_t randomLayer = pickRandomLayer();
 
-  if (randomLayer > (m_skipList.size() - 1))
+  while ( m_skipList.size() < randomLayer + 1)
     {
-      while ( (m_skipList.size() - 1) < randomLayer)
-        {
-          SkipListLayer* newLayer = new SkipListLayer();
-          m_skipList.push_back(newLayer);
+      SkipListLayer* newLayer = new SkipListLayer();
+      m_skipList.push_back(newLayer);
 
-          updateTable[(m_skipList.size() - 1)] = newLayer->begin();
-        }
+      updateTable[(m_skipList.size() - 1)] = newLayer->begin();
     }
 
-  int layer = 0;
-  for (SkipList::iterator i = m_skipList.begin(); i != m_skipList.end() && layer <= randomLayer; ++i)
+  size_t layer = 0;
+  for (SkipList::iterator i = m_skipList.begin();
+       i != m_skipList.end() && layer <= randomLayer; ++i)
     {
       if (updateTable[layer] == (*i)->end() && !insertInFront)
         {
@@ -213,7 +211,7 @@
   return false;
 }
 
-int
+size_t
 Cs::pickRandomLayer() const
 {
   int layer = -1;
@@ -226,7 +224,7 @@
     }
   while ( (randomValue < SKIPLIST_PROBABILITY) && (layer < SKIPLIST_MAX_LAYERS) );
 
-  return layer;
+  return static_cast<size_t>(layer);
 }
 
 bool
@@ -572,7 +570,7 @@
 
       BOOST_ASSERT(digest->size() == last.value_size());
       BOOST_ASSERT(digest->size() == ndn::crypto::SHA256_DIGEST_SIZE);
-      
+
       if (std::memcmp(digest->buf(), last.value(), ndn::crypto::SHA256_DIGEST_SIZE) != 0)
         {
           NFD_LOG_DEBUG("violates implicit digest");
@@ -584,9 +582,9 @@
     {
       if (interest.getMinSuffixComponents() >= 0)
         {
-          int minDataNameLength = interest.getName().size() + interest.getMinSuffixComponents();
+          size_t minDataNameLength = interest.getName().size() + interest.getMinSuffixComponents();
 
-          bool isSatisfied = minDataNameLength <= entry->getName().size();
+          bool isSatisfied = (minDataNameLength <= entry->getName().size());
           if ( !isSatisfied )
             {
               NFD_LOG_DEBUG("violates minComponents");
@@ -596,9 +594,9 @@
 
       if (interest.getMaxSuffixComponents() >= 0)
         {
-          int maxDataNameLength = interest.getName().size() + interest.getMaxSuffixComponents();
+          size_t maxDataNameLength = interest.getName().size() + interest.getMaxSuffixComponents();
 
-          bool isSatisfied = maxDataNameLength >= entry->getName().size();
+          bool isSatisfied = (maxDataNameLength >= entry->getName().size());
           if ( !isSatisfied )
             {
               NFD_LOG_DEBUG("violates maxComponents");
diff --git a/daemon/table/cs.hpp b/daemon/table/cs.hpp
index e4c1ae6..aeaec38 100644
--- a/daemon/table/cs.hpp
+++ b/daemon/table/cs.hpp
@@ -85,7 +85,7 @@
    *  Reference: "Skip Lists: A Probabilistic Alternative to Balanced Trees" by W.Pugh
    *  \return{ returns random layer (number) in a skip list}
    */
-  int
+  size_t
   pickRandomLayer() const;
 
   /** \brief Inserts a new Content Store Entry in a skip list
diff --git a/tests/mgmt/face-status-publisher-common.hpp b/tests/mgmt/face-status-publisher-common.hpp
index e6ff706..9df73b1 100644
--- a/tests/mgmt/face-status-publisher-common.hpp
+++ b/tests/mgmt/face-status-publisher-common.hpp
@@ -171,7 +171,7 @@
 
     m_buffer.appendByteArray(payload.value(), payload.value_size());
 
-    uint64_t segmentNo = data.getName()[-1].toSegment();
+    BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
     if (data.getFinalBlockId() != data.getName()[-1])
       {
         return;
diff --git a/tests/mgmt/fib-enumeration-publisher-common.hpp b/tests/mgmt/fib-enumeration-publisher-common.hpp
index 076a036..25bf215 100644
--- a/tests/mgmt/fib-enumeration-publisher-common.hpp
+++ b/tests/mgmt/fib-enumeration-publisher-common.hpp
@@ -155,7 +155,7 @@
 
     m_buffer.appendByteArray(payload.value(), payload.value_size());
 
-    uint64_t segmentNo = data.getName()[-1].toSegment();
+    BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
     if (data.getFinalBlockId() != data.getName()[-1])
       {
         return;
diff --git a/tests/mgmt/fib-manager.cpp b/tests/mgmt/fib-manager.cpp
index c230497..f388f47 100644
--- a/tests/mgmt/fib-manager.cpp
+++ b/tests/mgmt/fib-manager.cpp
@@ -21,7 +21,7 @@
 
 NFD_LOG_INIT("FibManagerTest");
 
-class FibManagerFixture : protected BaseFixture, public FibEnumerationPublisherFixture
+class FibManagerFixture : public FibEnumerationPublisherFixture
 {
 public:
 
diff --git a/tools/ndn-autoconfig-server.cpp b/tools/ndn-autoconfig-server.cpp
index 070b84c..18c063d 100644
--- a/tools/ndn-autoconfig-server.cpp
+++ b/tools/ndn-autoconfig-server.cpp
@@ -32,7 +32,6 @@
   void
   onInterest(const Name& name, const Interest& interest)
   {
-    size_t total_len = 0;
     ndn::Data data(ndn::Name(interest.getName()).appendVersion());
     data.setFreshnessPeriod(time::hours(1)); // 1 hour
     
diff --git a/wscript b/wscript
index 77b8e80..3010174 100644
--- a/wscript
+++ b/wscript
@@ -11,8 +11,6 @@
     nfdopt = opt.add_option_group('NFD Options')
     nfdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''')
     nfdopt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',help='''Build unit tests''')
-    nfdopt.add_option('--with-ndn-cpp',action='store',type='string',default=None,dest='ndn_cpp_dir',
-                      help='''Use NDN-CPP library from the specified path''')
 
 def configure(conf):
     conf.load("compiler_cxx boost gnu_dirs")
@@ -21,29 +19,30 @@
     except:
         pass
 
+    areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
     if conf.options.debug:
         conf.define('_DEBUG', 1)
-        conf.add_supported_cxxflags(cxxflags = ['-O0',
-                                                '-Wall',
-                                                '-Wno-unused-variable',
-                                                '-g3',
-                                                '-Wno-unused-private-field', # only clang supports
-                                                '-fcolor-diagnostics',       # only clang supports
-                                                '-Qunused-arguments',        # only clang supports
-                                                '-Wno-tautological-compare', # suppress warnings from CryptoPP
-                                                '-Wno-unused-function',      # suppress warnings from CryptoPP
-                                                '-fno-inline',
-                                                ])
-    else:
-        conf.add_supported_cxxflags(cxxflags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function'])
+        defaultFlags = ['-O0', '-g3',
+                        '-Werror',
+                        '-Wall',
+                        '-fcolor-diagnostics', # only clang supports
+                        ]
 
-    if not conf.options.ndn_cpp_dir:
-        conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDN_CPP', mandatory=True)
+        if areCustomCxxflagsPresent:
+            missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
+            if len(missingFlags) > 0:
+                Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
+                           % " ".join(conf.env.CXXFLAGS))
+                Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
+        else:
+            conf.add_supported_cxxflags(cxxflags = defaultFlags)
     else:
-        conf.check_cxx(lib='ndn-cpp-dev', uselib_store='NDN_CPP',
-                       cxxflags="-I%s/include" % conf.options.ndn_cpp_dir,
-                       linkflags="-L%s/lib" % conf.options.ndn_cpp_dir,
-                       mandatory=True)
+        defaultFlags = ['-O2', '-g', '-Wall']
+        if not areCustomCxxflagsPresent:
+            conf.add_supported_cxxflags(cxxflags = defaultFlags)
+
+    conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'],
+                   uselib_store='NDN_CPP', mandatory=True)
 
     boost_libs = 'system chrono program_options'
     if conf.options.with_tests:
@@ -64,9 +63,9 @@
     conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
     if conf.check_cxx(lib='pcap', uselib_store='PCAP', define_name='HAVE_PCAP', mandatory=False):
         conf.env['HAVE_PCAP'] = True
-    
+
     conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=True)
-    
+
     conf.load('coverage')
 
     conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nfd.conf' % conf.env['SYSCONFDIR'])
@@ -144,7 +143,7 @@
             supportedFlags += [flag]
 
     self.end_msg(' '.join (supportedFlags))
-    self.env.CXXFLAGS += supportedFlags
+    self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
 
 # doxygen docs
 from waflib.Build import BuildContext