Skip to content

Bug in ValueIteratorBase::operator- #169

Closed
@kevingrant

Description

@kevingrant

ValueIteratorBase::operator- implementation appears to be backwards. It calls this->computeDistance(other) and computeDistance expects that other is reachable from this (i.e. other >= this). But with iterators it1 - it2 generally implies that it1 is reachable from it2. Hence the following usage does not work as expected.

Repro

#include "json/json.h"
#include "stdio.h"

int main(int argc, char *argv[])
{
  Json::Value json;
  json["k1"] = "a";
  json["k2"] = "b";
  for (auto it = json.begin(); it != json.end(); ++it) {
    printf("Value #%d is %s\n", it - json.begin(), it->asString().c_str());
  }
  return 0;
}

Expected result

Value #0 is a
Value #1 is b

Actual result

Value #0 is a
<hang>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions