bstr: fix possible undefined behavior with length 0 strings

BSTR_P() passes the string length and start pointer to printf-like
functions. If the lenfth is 0, the pointer can be NULL, but we're
actually still not allowed to pass a NULL pointer in any case.

This is mostly a technically, because nobody in their right mind would
attempt to specifically break such cases. But it's still undefined
behavior, and some libcs might be strict about this.
This commit is contained in:
wm4 2015-01-12 14:43:52 +01:00 committed by Diogo Franco (Kovensky)
parent 947a791992
commit a44ffb729b
1 changed files with 1 additions and 1 deletions

View File

@ -207,7 +207,7 @@ static inline int bstr_eatstart0(struct bstr *s, const char *prefix)
}
// create a pair (not single value!) for "%.*s" printf syntax
#define BSTR_P(bstr) (int)((bstr).len), (bstr).start
#define BSTR_P(bstr) (int)((bstr).len), ((bstr).start ? (char*)(bstr).start : "")
#define WHITESPACE " \f\n\r\t\v"