Several corrections to make sure code compiles with gcc and doesn't generate warnings
Change-Id: I63e72ba724233953e9f36b11eca37070d6e06372
diff --git a/ccnx/ccnx-name.cpp b/ccnx/ccnx-name.cpp
index b7b04a6..55d434b 100644
--- a/ccnx/ccnx-name.cpp
+++ b/ccnx/ccnx-name.cpp
@@ -105,7 +105,7 @@
Name::Name(const unsigned char *data, const ccn_indexbuf *comps)
{
- for (int i = 0; i < comps->n - 1; i++)
+ for (unsigned int i = 0; i < comps->n - 1; i++)
{
const unsigned char *compPtr;
size_t size;
@@ -284,10 +284,15 @@
const Bytes &
Name::getComp(int index) const
{
- if (index >= m_comps.size())
- {
- boost::throw_exception(NameException() << error_info_str("Index out of range: " + boost::lexical_cast<string>(index)));
- }
+ if (index < 0)
+ {
+ boost::throw_exception(NameException() << error_info_str("Negative index: " + boost::lexical_cast<string>(index)));
+ }
+
+ if (static_cast<unsigned int> (index) >= m_comps.size())
+ {
+ boost::throw_exception(NameException() << error_info_str("Index out of range: " + boost::lexical_cast<string>(index)));
+ }
return m_comps[index];
}