CID 30742 Dereference before null check

CID 30741 ditto
This commit is contained in:
Enno Rehling 2015-11-05 10:58:08 +01:00
parent 0206ffbec6
commit 2a7fc87656
1 changed files with 26 additions and 20 deletions

View File

@ -606,7 +606,6 @@ int read_borders(struct storage *store)
for (;;) { for (;;) {
int bid = 0; int bid = 0;
char zText[32]; char zText[32];
connection *b;
region *from, *to; region *from, *to;
border_type *type; border_type *type;
@ -629,6 +628,10 @@ int read_borders(struct storage *store)
READ_INT(store, &tid); READ_INT(store, &tid);
from = findregionbyid(fid); from = findregionbyid(fid);
to = findregionbyid(tid); to = findregionbyid(tid);
if (!to || !from) {
log_warning("%s connection between incomplete regions %d and %d", zText, fid, tid);
continue;
}
} }
type = find_bordertype(zText); type = find_bordertype(zText);
@ -644,26 +647,29 @@ int read_borders(struct storage *store)
if (r != NULL) if (r != NULL)
to = r; to = r;
} }
b = new_border(type, from, to); if ((type->read && !type->write)) {
nextborder--; /* new_border erhöht den Wert */ log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0));
b->id = bid;
assert(bid <= nextborder);
if (type->read)
type->read(b, store);
if (global.data_version < NOBORDERATTRIBS_VERSION) {
attrib *a = NULL;
int result = a_read(store, &a, b);
if (border_convert_cb)
border_convert_cb(b, a);
while (a) {
a_remove(&a, a);
}
if (result < 0)
return result;
} }
if ((type->read && !type->write) || !to || !from) { else {
log_warning("erase invalid border '%s' between '%s' and '%s'\n", type->__name, regionname(from, 0), regionname(to, 0)); connection *b = new_border(type, from, to);
erase_border(b); nextborder--; /* new_border erhöht den Wert */
b->id = bid;
assert(bid <= nextborder);
if (type->read)
type->read(b, store);
if (global.data_version < NOBORDERATTRIBS_VERSION) {
attrib *a = NULL;
int result = a_read(store, &a, b);
if (border_convert_cb) {
border_convert_cb(b, a);
}
while (a) {
a_remove(&a, a);
}
if (result < 0) {
return result;
}
}
} }
} }
return 0; return 0;