Skip to content

Commit

Permalink
Merge pull request #44 from vasyahuyasa/fix_nullptr
Browse files Browse the repository at this point in the history
Fix nullptr
  • Loading branch information
vasyahuyasa authored Oct 31, 2018
2 parents cbf9fa3 + 2f3571f commit f1f0999
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions src/mod/banlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,27 @@ namespace remod
banlists.add(bl);
}

// Try to find banlist by name. If banlist absent create new one if name is null
// or empty string return local banlist
banlist* banmanager::getbanlist(char *name)
{
banlist *bl = NULL;
if(name && name[0])
// local banlist without name
if(!name || !name[0])
{
loopv(banlists)
if(strcmp(banlists[i]->name, name))
{
bl = banlists[i];
break;
}
return banlists[0];
}
else bl = banlists[0]; // local banlist without name
if(bl == NULL) bl = new banlist(name); // create new banlist
return bl;

banlist *bl = NULL;

// banlists[0]->name is always is null need to avoid it
loopv(banlists)
if(banlists[i]->name && strcmp(banlists[i]->name, name))
{
bl = banlists[i];
break;
}

return bl != NULL ? bl : new banlist(name);
}

banlist* banmanager::localbanlist()
Expand All @@ -76,14 +82,11 @@ namespace remod

baninfo* banmanager::getban(char *listname, size_t n)
{
if(banlistexists(listname))
{
banlist* bl = getbanlist(listname);
if(bl->bans.inrange(n))
return bl->bans[n];
else
return NULL;
}
if(!banlistexists(listname)) return NULL;

banlist* bl = getbanlist(listname);
if(bl->bans.inrange(n))
return bl->bans[n];
else
return NULL;
}
Expand Down Expand Up @@ -117,20 +120,22 @@ namespace remod

banlist *bl = getbanlist(listname);
bl->add(b);

// if banlist with listname not exist then add to it
if(!banlistexists(listname)) {
banlists.add(bl);
}
}

bool banmanager::delban(char *listname, int id)
{
if(banlistexists(listname))
if(!banlistexists(listname)) return false;

banlist *bl = getbanlist(listname);
if(bl->bans.inrange(id))
{
banlist *bl = getbanlist(listname);
if(bl->bans.inrange(id))
{
bl->bans.remove(id);
return true;
}
else
return false;
bl->bans.remove(id);
return true;
}
else
return false;
Expand Down

0 comments on commit f1f0999

Please sign in to comment.