Skip to content

Commit

Permalink
Same anti-segfault fix for simple dir comparison.
Browse files Browse the repository at this point in the history
Well, can only happen with (accidentally) empty item names. These
usually mean a programming error or other 'incident' on the system
examined, anyway ...
  • Loading branch information
erbth committed Feb 19, 2020
1 parent a892575 commit d6e3cf3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions SimpleDirectoryComparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,28 @@ bool SimpleDirectoryComparison::compare(

for (;;)
{
if (it1 == itemsD1.end() && it2 == itemsD2.end())
{
bool have_p1 = it1 != itemsD1.cend();
bool have_p2 = it2 != itemsD2.cend();

if (!have_p1 && !have_p2)
return equal;
}

string p1 = it1 != itemsD1.end() ? (*it1)->getName() : string();
string p2 = it2 != itemsD2.end() ? (*it2)->getName() : string();
string name_p1 = have_p1 ? (*it1)->getName() : string();
string name_p2 = have_p2 ? (*it2)->getName() : string();

if (!p1.empty() && ignoreItem(*it1, sp))
if (have_p1 && ignoreItem(*it1, sp))
{
it1++;
continue;
}

if (!p2.empty() && ignoreItem(*it2, sp))
if (have_p2 && ignoreItem(*it2, sp))
{
it2++;
continue;
}

if (p1 == p2)
if (have_p1 && have_p2 && name_p1 == name_p2)
{
if (!comparisonContext->compare(*it1, *it2))
{
Expand All @@ -135,7 +136,7 @@ bool SimpleDirectoryComparison::compare(
{
equal = false;

if (p2.empty() || !p1.empty() && p1.compare(p2) < 0)
if (!have_p2 || have_p1 && name_p1.compare(name_p2) < 0)
{
logIndentation(sp->getLog(), *it1);

Expand All @@ -150,11 +151,11 @@ bool SimpleDirectoryComparison::compare(
type = "directory ";
}

*(sp->getLog()) << type << "\"" << p1 << "\" not in directory 2" << endl;
*(sp->getLog()) << type << "\"" << name_p1 << "\" not in directory 2" << endl;

it1++;
}
else if (p1.empty() || !p2.empty() && p1.compare(p2) > 0)
else if (!have_p1 || have_p2 && name_p1.compare(name_p2) > 0)
{
logIndentation(sp->getLog(), *it2);

Expand All @@ -169,7 +170,7 @@ bool SimpleDirectoryComparison::compare(
type = "directory ";
}

*(sp->getLog()) << type << "\"" << p2 << "\" not in directory 1" << endl;
*(sp->getLog()) << type << "\"" << name_p2 << "\" not in directory 1" << endl;

it2++;
}
Expand Down

0 comments on commit d6e3cf3

Please sign in to comment.