derick Tue Aug 16 14:02:41 2005 EDT Modified files: /php-src/ext/standard php_smart_str.h /php-src/main spprintf.c Log: - 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. http://cvs.php.net/diff.php/php-src/ext/standard/php_smart_str.h?r1=1.31&r2=1.32&ty=u Index: php-src/ext/standard/php_smart_str.h diff -u php-src/ext/standard/php_smart_str.h:1.31 php-src/ext/standard/php_smart_str.h:1.32 --- php-src/ext/standard/php_smart_str.h:1.31 Sun Aug 14 13:14:40 2005 +++ php-src/ext/standard/php_smart_str.h Tue Aug 16 14:02:39 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_smart_str.h,v 1.31 2005/08/14 17:14:40 helly Exp $ */ +/* $Id: php_smart_str.h,v 1.32 2005/08/16 18:02:39 derick Exp $ */ #ifndef PHP_SMART_STR_H #define PHP_SMART_STR_H @@ -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) http://cvs.php.net/diff.php/php-src/main/spprintf.c?r1=1.31&r2=1.32&ty=u Index: php-src/main/spprintf.c diff -u php-src/main/spprintf.c:1.31 php-src/main/spprintf.c:1.32 --- php-src/main/spprintf.c:1.31 Mon Aug 15 03:19:10 2005 +++ php-src/main/spprintf.c Tue Aug 16 14:02:41 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spprintf.c,v 1.31 2005/08/15 07:19:10 dmitry Exp $ */ +/* $Id: spprintf.c,v 1.32 2005/08/16 18:02:41 derick Exp $ */ /* This is the spprintf implementation. * It has emerged from apache snprintf. See original header: @@ -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 @@ } 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 @@ 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;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php