]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 247335 via svnmerge from
authorMark Michelson <mmichelson@digium.com>
Wed, 17 Feb 2010 21:28:51 +0000 (21:28 +0000)
committerMark Michelson <mmichelson@digium.com>
Wed, 17 Feb 2010 21:28:51 +0000 (21:28 +0000)
https://origsvn.digium.com/svn/asterisk/trunk

........
  r247335 | mmichelson | 2010-02-17 15:22:40 -0600 (Wed, 17 Feb 2010) | 20 lines

  Fix two problems in ast_str functions found while writing a unit test.

  1. The documentation for ast_str_set and ast_str_append state that
  the max_len parameter may be -1 in order to limit the size of the
  ast_str to its current allocated size. The problem was that the max_len
  parameter in all cases was a size_t, which is unsigned. Thus a -1 was
  interpreted as UINT_MAX instead of -1. Changing the max_len parameter
  to be ssize_t fixed this issue.

  2. Once issue 1 was fixed, there was an off-by-one error in the case
  where we attempted to write a string larger than the current allotted
  size to a string when -1 was passed as the max_len parameter. When trying
  to write more than the allotted size, the ast_str's __AST_STR_USED was
  set to 1 higher than it should have been. Thanks to Tilghman for quickly
  spotting the offending line of code.

  Oh, and the unit test that I referenced in the top line of this commit
  will be added to reviewboard shortly. Sit tight...
........

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@247336 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/strings.h
main/utils.c

index 1e78c04c71b881bc79f3242fdb41556d7f52c41d..1438593027a76b5c4049957f2ec1854bcc92921a 100644 (file)
@@ -592,7 +592,7 @@ enum {
  *       through calling one of the other functions or macros defined in this
  *       file.
  */
-int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, size_t max_len,
+int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, ssize_t max_len,
                                                           int append, const char *fmt, va_list ap);
 
 /*!
@@ -633,7 +633,7 @@ int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf,
  * }
  * \endcode
  */
-AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct ast_str **buf, size_t max_len, const char *fmt, va_list ap),
+AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
 {
        return __ast_str_helper(buf, max_len, 0, fmt, ap);
 }
@@ -644,7 +644,7 @@ AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct a
  *
  * Same as ast_str_set_va(), but append to the current content.
  */
-AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struct ast_str **buf, size_t max_len, const char *fmt, va_list ap),
+AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
 {
        return __ast_str_helper(buf, max_len, 1, fmt, ap);
 }
@@ -669,7 +669,7 @@ AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struc
  */
 AST_INLINE_API(
 int __attribute__((format(printf, 3, 4))) ast_str_set(
-       struct ast_str **buf, size_t max_len, const char *fmt, ...),
+       struct ast_str **buf, ssize_t max_len, const char *fmt, ...),
 {
        int res;
        va_list ap;
@@ -690,7 +690,7 @@ int __attribute__((format(printf, 3, 4))) ast_str_set(
  */
 AST_INLINE_API(
 int __attribute__((format(printf, 3, 4))) ast_str_append(
-       struct ast_str **buf, size_t max_len, const char *fmt, ...),
+       struct ast_str **buf, ssize_t max_len, const char *fmt, ...),
 {
        int res;
        va_list ap;
index f82c20f2969428027b3190ab8ec8cd79f6a510bc..54300a3642965d4a26fcf0c48d131565c561c75c 100644 (file)
@@ -1762,7 +1762,7 @@ int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
  *     ast_str_append_va(...)
  */
 
-int __ast_str_helper(struct ast_str **buf, size_t max_len,
+int __ast_str_helper(struct ast_str **buf, ssize_t max_len,
        int append, const char *fmt, va_list ap)
 {
        int res, need;
@@ -1809,7 +1809,7 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len,
                break;
        } while (1);
        /* update space used, keep in mind the truncation */
-       (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
+       (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len - 1 : res + offset;
 
        return res;
 }