actofgod: Simplify fmtflags()'s error checking

Permit finding length by passing no buffer.  Not currently used.

Oops at most once.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-08-25 09:51:39 +02:00
parent 1a27107bed
commit 4f6a3c9aae

View file

@ -210,7 +210,7 @@ fmtflags (char *buf, size_t sz, int flags, struct symbol symtab[], int all)
int n, i;
char *p;
if (sz)
if (buf && sz)
buf[0] = 0;
n = 0;
for (i = 0; i < 32; i++) {
@ -221,12 +221,12 @@ fmtflags (char *buf, size_t sz, int flags, struct symbol symtab[], int all)
n += snprintf(buf + n, sz - n, "%s%s", sep, p);
else if (all)
n += snprintf(buf + n, sz - n, "%s#%d", sep, i);
if (CANT_HAPPEN((size_t)n >= sz)) {
buf = NULL;
if ((size_t)n >= sz)
sz = n;
}
sep = ", ";
}
CANT_HAPPEN((size_t)n >= sz && buf);
return n;
}