(oops): Cope with NULL argument passed by CANT_REACH().
/*
* If EXPR is true, an internal error occured.
* Return EXPR != 0.
- * Usage: if (CANT_HAPPEN(...)) recovery_code();
+ * Usage: if (CANT_HAPPEN(...)) <recovery code>;
*/
#define CANT_HAPPEN(expr) ((expr) ? oops(#expr, __FILE__, __LINE__) : 0)
+
+/*
+ * Report internal error.
+ * Usage: CANT_REACH(); <recovery code>;
+ */
+#define CANT_REACH() (void)oops(NULL, __FILE__, __LINE__)
+
extern int oops(char *, char *, int);
/* return codes from command routines */
built = build_plane(§, pp, sect.sct_item, tlev);
break;
default:
- CANT_HAPPEN("Bad WHAT");
+ CANT_REACH();
return RET_FAIL;
}
if (built) {
p = prland(ptr);
break;
default:
- CANT_HAPPEN("bad TYPE");
+ CANT_REACH();
p = "a red herring";
}
pr(" %4.0f ", real);
break;
default:
- CANT_HAPPEN("bad TYPE");
+ CANT_REACH();
pr(" ??? ");
break;
}
pr("%snil", sep);
break;
default:
- CANT_HAPPEN("Bad VAL type");
+ CANT_REACH();
pr("0");
}
return " ";
int
oops(char *msg, char *file, int line)
{
- logerror("Oops: %s in %s:%d", msg, file, line);
+ logerror("Oops: %s in %s:%d", msg ? msg : "bug", file, line);
if (debug) abort();
return 1;
}
int c;
switch (bmap) {
default:
- CANT_HAPPEN("bad BMAP");
+ CANT_REACH();
bmap = 'b';
/* fall through */
case 'b':
empth_exit();
- CANT_HAPPEN("main thread terminated");
+ CANT_REACH();
finish_server();
}
return 0;
break;
default:
- CANT_HAPPEN("bad OPTYPE");
+ CANT_REACH();
return 0;
}
}
valtype = NSC_STRING;
break;
default:
- CANT_HAPPEN("bad VALTYPE");
+ CANT_REACH();
valtype = NSC_NOTYPE;
}
return valtype;
case NSC_LONG:
return cond_type_mismatch(str);
default:
- CANT_HAPPEN("bad TO argument");
+ CANT_REACH();
to = from;
}
}
switch (val->val_cat) {
default:
- CANT_HAPPEN("Bad VAL category");
+ CANT_REACH();
/* fall through */
case NSC_VAL:
valtype = val->val_type;
valtype = NSC_TYPEID;
break;
default:
- CANT_HAPPEN("Bad VAL type");
+ CANT_REACH();
val->val_as.lng = 0;
}
val->val_cat = NSC_VAL;
val->val_as.dbl = val->val_as.lng;
}
} else if (want == NSC_STRING)
- CANT_HAPPEN("unimplemented WANT"); /* FIXME */
+ CANT_REACH(); /* FIXME implement */
if (CANT_HAPPEN(valtype != want && want != NSC_NOTYPE)) {
valtype = want;
case NSC_DOUBLE: val->val_as.dbl = 0.0; break;
case NSC_STRING: val->val_as.str.base = NULL; break;
default:
- CANT_HAPPEN("bad WANT argument");
+ CANT_REACH();
}
}
selected = 0;
break;
default:
- CANT_HAPPEN("bad np->sel");
+ CANT_REACH();
return 0;
}
if (selected && np->ncond) {
return check_ship_ok(&tgp->shp);
if (tgp->gen.ef_type == EF_NUKE)
return check_nuke_ok(&tgp->nuk);
- CANT_HAPPEN("Bad EF_TYPE");
+ CANT_REACH();
pr("Trade lot went bad!\n");
return 0;
}
selected = 0;
break;
default:
- CANT_HAPPEN("bad np->sel");
+ CANT_REACH();
return 0;
}
if (selected && np->ncond) {
empth_exit();
- CANT_HAPPEN("main thread terminated");
+ CANT_REACH();
finish_server();
return EXIT_SUCCESS;
}