From 8c82b2815efbbc4d974ce91f7013ca1e71dd5f68 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 4 Feb 2007 13:30:06 +0000 Subject: [PATCH] more crashes caused by shipowner==NULL --- src/common/gamecode/creport.c | 2 +- src/common/gamecode/report.c | 2 +- src/common/kernel/build.c | 1 - src/common/kernel/movement.c | 6 ++-- src/common/kernel/spy.c | 64 +++++++++++++++++++---------------- src/eressea/korrektur.c | 2 +- 6 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 1dfd3e53e..1b3ffcdff 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -192,7 +192,7 @@ print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ) unit * owner = shipowner(sh); a = sh->attribs; r = sh->region; - if(owner != NULL) { + if (owner != NULL) { if (owner->faction == viewer){ self = 2; } else { /* steht eine person der Partei auf dem Schiff? */ diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 5fc972f4a..f08a729b6 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -449,7 +449,7 @@ print_curses(FILE *F, const faction *viewer, const void * obj, typ_t typ, int in unit * owner = shipowner(sh); a = sh->attribs; r = sh->region; - if((owner) != NULL){ + if (owner) { if (owner->faction == viewer){ self = 2; } else { /* steht eine person der Partei auf dem Schiff? */ diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index f7323d787..adb71dc22 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -1102,7 +1102,6 @@ mayboard(const unit * u, const ship * sh) unit *u2 = shipowner(sh); return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD)); - } int diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 568afbf1b..13d4a7ccd 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -652,8 +652,10 @@ ship_allowed(const struct ship * sh, const region * r) if (is_freezing(u)) { unit * captain = shipowner(sh); - ADDMSG(&captain->faction->msgs, msg_message("detectforbidden", - "unit region", u, r)); + if (captain) { + ADDMSG(&captain->faction->msgs, msg_message("detectforbidden", + "unit region", u, r)); + } return false; } diff --git a/src/common/kernel/spy.c b/src/common/kernel/spy.c index 6a95f5f4a..d0ba00ab8 100644 --- a/src/common/kernel/spy.c +++ b/src/common/kernel/spy.c @@ -494,36 +494,42 @@ crew_skill(region * r, faction * f, ship * sh, skill_t sk) static int try_destruction(unit * u, unit * u2, const char *name, int skilldiff) { - const char *destruction_success_msg = "%s wurde von %s zerstoert."; - const char *destruction_failed_msg = "%s konnte %s nicht zerstoeren."; - const char *destruction_detected_msg = "%s wurde beim Versuch, %s zu zerstoeren, entdeckt."; - const char *detect_failure_msg = "Es wurde versucht, %s zu zerstoeren."; - const char *object_destroyed_msg = "%s wurde zerstoert."; + const char *destruction_success_msg = "%s wurde von %s zerstoert."; + const char *destruction_failed_msg = "%s konnte %s nicht zerstoeren."; + const char *destruction_detected_msg = "%s wurde beim Versuch, %s zu zerstoeren, entdeckt."; + const char *detect_failure_msg = "Es wurde versucht, %s zu zerstoeren."; + const char *object_destroyed_msg = "%s wurde zerstoert."; - if (skilldiff == 0) { - /* tell the unit that the attempt failed: */ - sprintf(buf, destruction_failed_msg, unitname(u), name); - addmessage(0, u->faction, buf, MSG_EVENT, ML_WARN); - /* tell the enemy about the attempt: */ - sprintf(buf, detect_failure_msg, name); - addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); - return 0; - } - if (skilldiff < 0) { - /* tell the unit that the attempt was detected: */ - sprintf(buf, destruction_detected_msg, unitname(u), name); - addmessage(0, u->faction, buf, MSG_EVENT, ML_WARN); - /* tell the enemy whodunit: */ - sprintf(buf, detect_failure_msg, unitname(u2), unitname(u), name); - addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); - return 0; - } - /* tell the unit that the attempt succeeded */ - sprintf(buf, destruction_success_msg, name, unitname(u)); - addmessage(0, u->faction, buf, MSG_EVENT, ML_INFO); - sprintf(buf, object_destroyed_msg, name); - addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); - return 1; /* success */ + if (skilldiff == 0) { + /* tell the unit that the attempt failed: */ + sprintf(buf, destruction_failed_msg, unitname(u), name); + addmessage(0, u->faction, buf, MSG_EVENT, ML_WARN); + /* tell the enemy about the attempt: */ + if (u2) { + sprintf(buf, detect_failure_msg, name); + addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); + } + return 0; + } + if (skilldiff < 0) { + /* tell the unit that the attempt was detected: */ + sprintf(buf, destruction_detected_msg, unitname(u), name); + addmessage(0, u->faction, buf, MSG_EVENT, ML_WARN); + /* tell the enemy whodunit: */ + if (u2) { + sprintf(buf, detect_failure_msg, unitname(u2), unitname(u), name); + addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); + } + return 0; + } + /* tell the unit that the attempt succeeded */ + sprintf(buf, destruction_success_msg, name, unitname(u)); + addmessage(0, u->faction, buf, MSG_EVENT, ML_INFO); + if (u2) { + sprintf(buf, object_destroyed_msg, name); + addmessage(0, u2->faction, buf, MSG_EVENT, ML_IMPORTANT); + } + return 1; /* success */ } static void diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 66cab9eed..fc60d0488 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -164,7 +164,7 @@ verify_owners(boolean bOnce) } if (u->ship) { unit * bo = shipowner(u->ship); - if (!fval(bo, UFL_OWNER)) { + if (bo && !fval(bo, UFL_OWNER)) { log_error(("[verify_owners] %u ist Besitzer von %s, hat aber UFL_OWNER nicht.\n", unitname(bo), shipname(u->ship))); bFail = true; if (bOnce) break;