diff options
author | Walter Doekes <walter+asterisk@wjd.nu> | 2011-11-23 19:58:19 +0000 |
---|---|---|
committer | Walter Doekes <walter+asterisk@wjd.nu> | 2011-11-23 19:58:19 +0000 |
commit | b7aee9ebc9e61ad592f1924ceff160ccab1b1ad5 (patch) | |
tree | 0478adac0753a719c8076e263f941867f5f2e6a4 /include | |
parent | e6ca7680812d1ecbf45419ca92bcadacbd6fa47f (diff) |
Fix ast_str_truncate signedness warning and documentation.
Review: https://reviewboard.asterisk.org/r/1594
........
Merged revisions 346144 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 346145 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@346146 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/strings.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 2a8b0e490..5827dda9b 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -498,14 +498,20 @@ char * attribute_pure ast_str_buffer(const struct ast_str *buf), /*!\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; } |