/*!\brief Truncates the enclosed string to the given length.
* \param buf A pointer to the ast_str structure.
- * \param len Maximum length of the string.
+ * \param len Maximum length of the string. If len is larger than the
+ * current maximum length, things will explode. If it is negative
+ * at most -len characters will be trimmed off the end.
* \retval A pointer to the resulting string.
*/
AST_INLINE_API(
char *ast_str_truncate(struct ast_str *buf, ssize_t len),
{
if (len < 0) {
- buf->__AST_STR_USED += ((ssize_t) abs(len)) > (ssize_t) buf->__AST_STR_USED ? -buf->__AST_STR_USED : len;
+ if ((typeof(buf->__AST_STR_USED)) -len >= buf->__AST_STR_USED) {
+ buf->__AST_STR_USED = 0;
+ } else {
+ buf->__AST_STR_USED += len;
+ }
} else {
buf->__AST_STR_USED = len;
}