strings.h: Ensure ast_str_buffer(…) returns a 0 terminated string.

If a dynamic string is created with an initial length of 0,
`ast_str_buffer(…)` will return an invalid pointer.

This was a secondary discovery when fixing #65.
pull/628/head
Sean Bright 2 years ago
parent e62939b183
commit 164001b05c

@ -753,8 +753,11 @@ char * attribute_pure ast_str_buffer(const struct ast_str *buf),
* being returned; eventually, it should become truly const * being returned; eventually, it should become truly const
* and only be modified via accessor functions * and only be modified via accessor functions
*/ */
if (__builtin_expect(buf->__AST_STR_LEN > 0, 1)) {
return (char *) buf->__AST_STR_STR; return (char *) buf->__AST_STR_STR;
} }
return "";
}
) )
/*! /*!

Loading…
Cancel
Save