- Fixed a couple of bugs in the new smart_str macros, and allow them to

allocate two extra bytes (so that we can pad them with two \0's for UTF-16)
- Fixed usage of smart_str's in the PAD and INS_STRING macros.
This commit is contained in:
Derick Rethans 2005-08-16 18:02:41 +00:00
parent 5adc3ce7c6
commit 1ee41e0d92
2 changed files with 15 additions and 13 deletions

View File

@ -28,9 +28,12 @@
#include <zend.h>
#endif
/* It's safe to write to "one behind the length" as we allocate two extra bytes
* to allow for Unicode trailers */
#define smart_str_0(x) do { \
if ((x)->c) { \
(x)->c[(x)->len] = '\0'; \
(x)->c[(x)->len + 1] = '\0'; \
} \
} while (0)
@ -49,7 +52,7 @@
#endif
#define SMART_STR_DO_REALLOC(d, what) \
(d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 1, (what))
(d)->c = SMART_STR_REALLOC((d)->c, (d)->a + 2, (what))
#define smart_str_alloc4(d, n, what, newlen) do { \
if (!(d)->c) { \
@ -78,15 +81,15 @@
#define smart_str_appends(dest, src) \
smart_str_appendl((dest), (src), strlen(src))
/* normall character appending */
/* normal character appending */
#define smart_str_appendc(dest, c) \
smart_str_appendc_ex((dest), (c), 0)
/* appending of a single UTF-16 code unit (2 byte)*/
#define smart_str_append2c(dest, c) while (0) { \
#define smart_str_append2c(dest, c) do { \
smart_str_appendc_ex((dest), (c&0xFF), 0); \
smart_str_appendc_ex((dest), (c&0xFF00 ? c>>8 : '\0'), 0); \
}
} while (0)
#define smart_str_free(s) \
smart_str_free_ex((s), 0)

View File

@ -126,22 +126,22 @@
} \
} while (0)
#define INS_STRING(unicode, s_uni, xbuf, s, slen) \
#define INS_STRING(unicode, s_unicode, xbuf, s, s_len) \
do { \
if (unicode) { \
size_t newlen, p, sz = 2*(slen); \
size_t newlen, p, sz = 2*(s_len); \
smart_str_alloc(xbuf, (sz), 0); \
if (s_uni) { \
if (s_unicode) { \
memcpy(xbuf->c + xbuf->len, s, (sz)); \
} else { \
p = (slen); \
p = (s_len); \
while(p--) { \
smart_str_append2c(xbuf, *s++); \
smart_str_append2c(xbuf, *s); \
*s++; \
} \
} \
xbuf->len += (sz); \
} else { \
smart_str_appendl(xbuf, s, slen); \
smart_str_appendl(xbuf, s, s_len); \
} \
} while (0)
@ -163,8 +163,8 @@ do { \
} else { \
smart_str_alloc(xbuf, sz, 0); \
memset(xbuf->c + xbuf->len, ch, sz); \
xbuf->len += sz; \
} \
xbuf->len += sz; \
} \
} while (0)
@ -847,7 +847,6 @@ PHPAPI int vuspprintf(char **pbuf, size_t max_len, const char *format, va_list a
if (max_len && xbuf.len > max_len) {
xbuf.len = max_len;
}
smart_str_appendc(&xbuf, '\0'); /* we need \0\0 as termination */
smart_str_0(&xbuf);
*pbuf = xbuf.c;