[asterisk-commits] mmichelson: branch 1.6.2 r247337 - in /branches/1.6.2: ./ include/asterisk/ m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Feb 17 15:32:22 CST 2010
Author: mmichelson
Date: Wed Feb 17 15:32:18 2010
New Revision: 247337
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247337
Log:
Merged revisions 247335 via svnmerge from
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...
........
Modified:
branches/1.6.2/ (props changed)
branches/1.6.2/include/asterisk/strings.h
branches/1.6.2/main/strings.c
Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Modified: branches/1.6.2/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/include/asterisk/strings.h?view=diff&rev=247337&r1=247336&r2=247337
==============================================================================
--- branches/1.6.2/include/asterisk/strings.h (original)
+++ branches/1.6.2/include/asterisk/strings.h Wed Feb 17 15:32:18 2010
@@ -699,14 +699,14 @@
* file.
*/
#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
-int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, size_t max_len,
+int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func);
#define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)
#else
-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);
#endif
-char *__ast_str_helper2(struct ast_str **buf, size_t max_len,
+char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,
const char *src, size_t maxsrc, int append, int escapecommas);
/*!
@@ -747,7 +747,7 @@
* }
* \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);
}
@@ -758,35 +758,35 @@
*
* 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);
}
)
/*!\brief Set a dynamic string to a non-NULL terminated substring. */
-AST_INLINE_API(char *ast_str_set_substr(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc),
+AST_INLINE_API(char *ast_str_set_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc),
{
return __ast_str_helper2(buf, maxlen, src, maxsrc, 0, 0);
}
)
/*!\brief Append a non-NULL terminated substring to the end of a dynamic string. */
-AST_INLINE_API(char *ast_str_append_substr(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc),
+AST_INLINE_API(char *ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc),
{
return __ast_str_helper2(buf, maxlen, src, maxsrc, 1, 0);
}
)
/*!\brief Set a dynamic string to a non-NULL terminated substring, with escaping of commas. */
-AST_INLINE_API(char *ast_str_set_escapecommas(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc),
+AST_INLINE_API(char *ast_str_set_escapecommas(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc),
{
return __ast_str_helper2(buf, maxlen, src, maxsrc, 0, 1);
}
)
/*!\brief Append a non-NULL terminated substring to the end of a dynamic string, with escaping of commas. */
-AST_INLINE_API(char *ast_str_append_escapecommas(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc),
+AST_INLINE_API(char *ast_str_append_escapecommas(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc),
{
return __ast_str_helper2(buf, maxlen, src, maxsrc, 1, 1);
}
@@ -811,7 +811,7 @@
*/
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;
@@ -832,7 +832,7 @@
*/
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;
Modified: branches/1.6.2/main/strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/main/strings.c?view=diff&rev=247337&r1=247336&r2=247337
==============================================================================
--- branches/1.6.2/main/strings.c (original)
+++ branches/1.6.2/main/strings.c Wed Feb 17 15:32:18 2010
@@ -49,10 +49,10 @@
*/
#if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
-int __ast_debug_str_helper(struct ast_str **buf, size_t max_len,
+int __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function)
#else
-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)
#endif
{
@@ -106,7 +106,7 @@
break;
} while (1);
/* update space used, keep in mind the truncation */
- (*buf)->__AST_STR_USED = (res + offset > (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_LEN : res + offset;
+ (*buf)->__AST_STR_USED = (res + offset > (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_LEN - 1 : res + offset;
return res;
}
@@ -122,7 +122,7 @@
} while (maxlen == 0 && (*buf)->__AST_STR_LEN - 5 < (*buf)->__AST_STR_USED);
}
-char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas)
+char *__ast_str_helper2(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas)
{
int dynamic = 0;
char *ptr = append ? &((*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED]) : (*buf)->__AST_STR_STR;
More information about the asterisk-commits
mailing list