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,7 +647,11 @@ 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)) {
log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0));
}
else {
connection *b = new_border(type, from, to);
nextborder--; /* new_border erhöht den Wert */ nextborder--; /* new_border erhöht den Wert */
b->id = bid; b->id = bid;
assert(bid <= nextborder); assert(bid <= nextborder);
@ -653,17 +660,16 @@ int read_borders(struct storage *store)
if (global.data_version < NOBORDERATTRIBS_VERSION) { if (global.data_version < NOBORDERATTRIBS_VERSION) {
attrib *a = NULL; attrib *a = NULL;
int result = a_read(store, &a, b); int result = a_read(store, &a, b);
if (border_convert_cb) if (border_convert_cb) {
border_convert_cb(b, a); border_convert_cb(b, a);
}
while (a) { while (a) {
a_remove(&a, a); a_remove(&a, a);
} }
if (result < 0) if (result < 0) {
return result; return result;
} }
if ((type->read && !type->write) || !to || !from) { }
log_warning("erase invalid border '%s' between '%s' and '%s'\n", type->__name, regionname(from, 0), regionname(to, 0));
erase_border(b);
} }
} }
return 0; return 0;