Skip to content
Permalink
Browse files

Correct off-by-one error in address table indices

Commit d809f23 changed the indices of this for loop from being
0-based to 1-based, but did not update the index into the contact
object's "address" member accordingly to be zero-based. This meant that
the value defined in the "address1" attribute of contact objects was
made available in the "address2" attribute in LiveStatus query results,
and "address2" in "address3" etc, per the definitions for the contact
object in in nagios/objects.h and nagios4/objects.h.

This change restores the zero base case for the loop index, but sets
both the 1-based directive name and the 0-based array index correctly,
restoring the expected behaviour.
  • Loading branch information...
Tom Ryder authored and svenpanne committed Jan 29, 2018
1 parent b9bbc5d commit 81f893c23f081f50946b32131be58ec6986fa992
Showing with 2 additions and 2 deletions.
  1. +2 −2 livestatus/src/TableContacts.cc
@@ -71,8 +71,8 @@ void TableContacts::addColumns(Table *table, const std::string &prefix,
"The time period in which the contact will be notified about service problems",
indirect_offset, -1, -1,
DANGEROUS_OFFSETOF(contact, service_notification_period)));
for (int i = 1; i <= MAX_CONTACT_ADDRESSES; ++i) {
std::string b = "address" + std::to_string(i);
for (int i = 0; i < MAX_CONTACT_ADDRESSES; ++i) {
std::string b = "address" + std::to_string(i + 1);
table->addColumn(std::make_unique<OffsetStringColumn>(
prefix + b, "The additional field " + b, indirect_offset, -1, -1,
DANGEROUS_OFFSETOF(contact, address[i])));

0 comments on commit 81f893c

Please sign in to comment.
You can’t perform that action at this time.