Skip to content

Commit 0863915

Browse files
esyrldv-alt
authored andcommitted
xlat.c: return NULL in sprintflags if there are no flags
Otherwise the auxstr is rather ugly at times. * xlat.c (sprintflags): Return NULL if no flags were printed.
1 parent b21d81d commit 0863915

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xlat.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ addflags(const struct xlat *xlat, uint64_t flags)
160160
/*
161161
* Interpret `xlat' as an array of flags.
162162
* Print to static string the entries whose bits are on in `flags'
163-
* Return static string.
163+
* Return static string. If 0 is provided as flags, and there is no flag that
164+
* has the value of 0 (it should be the first in xlat table), return NULL.
164165
*/
165166
const char *
166167
sprintflags(const char *prefix, const struct xlat *xlat, uint64_t flags)
@@ -187,10 +188,14 @@ sprintflags(const char *prefix, const struct xlat *xlat, uint64_t flags)
187188
break;
188189
}
189190
}
191+
190192
if (flags) {
191193
if (found)
192194
*outptr++ = '|';
193195
outptr = xappendstr(outstr, outptr, "%#" PRIx64, flags);
196+
} else {
197+
if (!found)
198+
return NULL;
194199
}
195200

196201
return outstr;

0 commit comments

Comments
 (0)