Fix a couple of dangling-reference and maybe-uninitialized warnings

Change-Id: Iac5df0dbe8400c93ff825c1cecd96933292a3b81
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index be197d6..842ab39 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2017-2022, Regents of the University of California.
+ * Copyright (c) 2017-2023, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -121,10 +121,8 @@
 CaModule::getCaProfileData()
 {
   if (m_profileData == nullptr) {
-    const auto& pib = m_keyChain.getPib();
-    const auto& identity = pib.getIdentity(m_config.caProfile.caPrefix);
-    const auto& cert = identity.getDefaultKey().getDefaultCertificate();
-    Block contentTLV = infotlv::encodeDataContent(m_config.caProfile, cert);
+    auto key = m_keyChain.getPib().getIdentity(m_config.caProfile.caPrefix).getDefaultKey();
+    Block contentTLV = infotlv::encodeDataContent(m_config.caProfile, key.getDefaultCertificate());
 
     Name infoPacketName(m_config.caProfile.caPrefix);
     auto segmentComp = ndn::name::Component::fromSegment(0);
@@ -153,7 +151,8 @@
 }
 
 void
-CaModule::onProbe(const Interest& request) {
+CaModule::onProbe(const Interest& request)
+{
   // PROBE Naming Convention: /<CA-Prefix>/CA/PROBE/[ParametersSha256DigestComponent]
   NDN_LOG_TRACE("Received PROBE request");
 
@@ -163,19 +162,20 @@
   try {
     auto parameters = probetlv::decodeApplicationParameters(request.getApplicationParameters());
 
-    //collect redirections
+    // collect redirections
     for (auto &item : m_config.redirection) {
       if (item.second->isRedirecting(parameters)) {
         redirectionNames.push_back(item.first->getFullName());
       }
     }
 
-    //collect name assignments
+    // collect name assignments
     for (auto &item : m_config.nameAssignmentFuncs) {
       auto names = item->assignName(parameters);
       availableComponents.insert(availableComponents.end(), names.begin(), names.end());
     }
-  } catch (const std::exception& e) {
+  }
+  catch (const std::exception& e) {
     NDN_LOG_ERROR("[CaModule::onProbe]Error in decoding TLV: " << e.what());
     return;
   }
@@ -195,8 +195,8 @@
 
   Data result;
   result.setName(request.getName());
-  result.setContent(
-      probetlv::encodeDataContent(availableNames, m_config.caProfile.maxSuffixLength, redirectionNames));
+  result.setContent(probetlv::encodeDataContent(availableNames, m_config.caProfile.maxSuffixLength,
+                                                redirectionNames));
   result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
   m_keyChain.sign(result, signingByIdentity(m_config.caProfile.caPrefix));
   m_face.put(result);
@@ -206,11 +206,11 @@
 void
 CaModule::onNewRenewRevoke(const Interest& request, RequestType requestType)
 {
-  //verify ca cert validity
-  const auto& caCert = m_keyChain.getPib()
-                                 .getIdentity(m_config.caProfile.caPrefix)
-                                 .getDefaultKey()
-                                 .getDefaultCertificate();
+  // verify ca cert validity
+  auto caCert = m_keyChain.getPib()
+                          .getIdentity(m_config.caProfile.caPrefix)
+                          .getDefaultKey()
+                          .getDefaultCertificate();
   if (!caCert.isValid()) {
     NDN_LOG_ERROR("Server certificate invalid/expired");
     m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_VALIDITY_PERIOD,
diff --git a/src/detail/error-encoder.cpp b/src/detail/error-encoder.cpp
index 3dcb6ca..09197c9 100644
--- a/src/detail/error-encoder.cpp
+++ b/src/detail/error-encoder.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2017-2022, Regents of the University of California.
+ * Copyright (c) 2017-2023, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -39,14 +39,15 @@
 {
   try {
     block.parse();
+
     int codeCount = 0;
     int infoCount = 0;
     int otherCriticalCount = 0;
-    ErrorCode error;
+    ErrorCode error = ErrorCode::NO_ERROR;
     std::string errorInfo;
     for (const auto& item : block.elements()) {
       if (item.type() == tlv::ErrorCode) {
-        error = static_cast<ErrorCode>(readNonNegativeInteger(block.get(tlv::ErrorCode)));
+        error = ndn::readNonNegativeIntegerAs<ErrorCode>(block.get(tlv::ErrorCode));
         codeCount++;
       }
       else if (item.type() == tlv::ErrorInfo) {
@@ -57,9 +58,10 @@
         otherCriticalCount++;
       }
       else {
-        //ignore
+        // ignore
       }
     }
+
     if (codeCount == 0 && infoCount == 0) {
       return {ErrorCode::NO_ERROR, ""};
     }
@@ -68,7 +70,7 @@
                                    std::to_string(infoCount) + " error info(s), instead of expected 1 time each."));
     }
     if (otherCriticalCount > 0) {
-      NDN_THROW(std::runtime_error("Unknown Critical TLV type in error packet"));
+      NDN_THROW(std::runtime_error("Unknown critical TLV type in error packet"));
     }
     return {error, errorInfo};
   }