prnatid: Recover from getnatp() failure

cname() calls getnatp(), and returns a null pointer when it fails.
Some systems (GNU, Windows) deal gracefully with printing null
strings, others crash.

Because we keep table EF_NATION entirely in memory, getnatp() should
fail only on invalid country number.

Rewrite prnatid() to catch this error and recover.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-01-14 23:18:11 +01:00
parent 61a32b8b69
commit 44fbf6cd30

View file

@ -82,5 +82,9 @@ prnat(struct natstr *np)
char * char *
prnatid(natid cnum) prnatid(natid cnum)
{ {
return prbuf("%s (#%d)", cname(cnum), cnum); struct natstr *np = getnatp(cnum);
if (CANT_HAPPEN(!np))
return prbuf("%d (#%d)", cnum, cnum);
return prnat(np);
} }