diff options
Diffstat (limited to 'ext/mbstring/libmbfl/mbfl')
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfilter.c | 321 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfilter.h | 10 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c | 6 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfilter_pass.c | 3 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_allocators.c | 3 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_allocators.h | 9 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_convert.c | 16 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_encoding.c | 1 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_ident.c | 18 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c | 51 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_string.c | 30 | ||||
-rw-r--r-- | ext/mbstring/libmbfl/mbfl/mbfl_string.h | 3 |
12 files changed, 142 insertions, 329 deletions
diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 4da5a231a4..f81589b806 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -83,6 +83,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "zend_operators.h" #include <stddef.h> #include <string.h> @@ -123,15 +124,7 @@ mbfl_buffer_converter_new( const mbfl_encoding *to, size_t buf_initsz) { - mbfl_buffer_converter *convd; - - /* allocate */ - convd = (mbfl_buffer_converter*)mbfl_malloc(sizeof(mbfl_buffer_converter)); - if (convd == NULL) { - return NULL; - } - - /* initialize */ + mbfl_buffer_converter *convd = mbfl_malloc(sizeof(mbfl_buffer_converter)); convd->from = from; convd->to = to; @@ -375,15 +368,8 @@ mbfl_encoding_detector_new(const mbfl_encoding **elist, int elistsz, int strict) } /* allocate */ - identd = (mbfl_encoding_detector*)mbfl_malloc(sizeof(mbfl_encoding_detector)); - if (identd == NULL) { - return NULL; - } - identd->filter_list = (mbfl_identify_filter **)mbfl_calloc(elistsz, sizeof(mbfl_identify_filter *)); - if (identd->filter_list == NULL) { - mbfl_free(identd); - return NULL; - } + identd = mbfl_malloc(sizeof(mbfl_encoding_detector)); + identd->filter_list = mbfl_calloc(elistsz, sizeof(mbfl_identify_filter *)); /* create filters */ i = 0; @@ -571,10 +557,7 @@ mbfl_identify_encoding(mbfl_string *string, const mbfl_encoding **elist, int eli const mbfl_encoding *encoding; /* flist is an array of mbfl_identify_filter instances */ - flist = (mbfl_identify_filter *)mbfl_calloc(elistsz, sizeof(mbfl_identify_filter)); - if (flist == NULL) { - return NULL; - } + flist = mbfl_calloc(elistsz, sizeof(mbfl_identify_filter)); num = 0; if (elist != NULL) { @@ -657,7 +640,7 @@ filter_count_output(int c, void *data) } size_t -mbfl_strlen(mbfl_string *string) +mbfl_strlen(const mbfl_string *string) { size_t len, n, k; unsigned char *p; @@ -810,6 +793,49 @@ mbfl_oddlen(mbfl_string *string) /* NOT REACHED */ } +static const unsigned char *mbfl_find_offset_utf8( + const unsigned char *str, const unsigned char *end, ssize_t offset) { + if (offset < 0) { + const unsigned char *pos = end; + while (offset < 0) { + if (pos <= str) { + return NULL; + } + + unsigned char c = *(--pos); + if (c < 0x80) { + ++offset; + } else if ((c & 0xc0) != 0x80) { + ++offset; + } + } + return pos; + } else { + const unsigned char *u8_tbl = mbfl_encoding_utf8.mblen_table; + const unsigned char *pos = str; + while (offset-- > 0) { + if (pos >= end) { + return NULL; + } + pos += u8_tbl[*pos]; + } + return pos; + } +} + +static size_t mbfl_pointer_to_offset_utf8(const unsigned char *start, const unsigned char *pos) { + size_t result = 0; + while (pos > start) { + unsigned char c = *--pos; + if (c < 0x80) { + ++result; + } else if ((c & 0xc0) != 0x80) { + ++result; + } + } + return result; +} + size_t mbfl_strpos( mbfl_string *haystack, @@ -820,25 +846,13 @@ mbfl_strpos( size_t result; mbfl_string _haystack_u8, _needle_u8; const mbfl_string *haystack_u8, *needle_u8 = NULL; - const unsigned char *u8_tbl; - - if (haystack == NULL || haystack->val == NULL || needle == NULL || needle->val == NULL) { - return (size_t) -8; - } - - { - const mbfl_encoding *u8_enc = &mbfl_encoding_utf8; - if (u8_enc->mblen_table == NULL) { - return (size_t) -8; - } - u8_tbl = u8_enc->mblen_table; - } + const unsigned char *offset_pointer; if (haystack->encoding->no_encoding != mbfl_no_encoding_utf8) { mbfl_string_init(&_haystack_u8); haystack_u8 = mbfl_convert_encoding(haystack, &_haystack_u8, &mbfl_encoding_utf8); if (haystack_u8 == NULL) { - result = (size_t) -4; + result = MBFL_ERROR_ENCODING; goto out; } } else { @@ -849,163 +863,56 @@ mbfl_strpos( mbfl_string_init(&_needle_u8); needle_u8 = mbfl_convert_encoding(needle, &_needle_u8, &mbfl_encoding_utf8); if (needle_u8 == NULL) { - result = (size_t) -4; + result = MBFL_ERROR_ENCODING; goto out; } } else { needle_u8 = needle; } - if (needle_u8->len < 1) { - result = (size_t) -8; + offset_pointer = mbfl_find_offset_utf8( + haystack_u8->val, haystack_u8->val + haystack_u8->len, offset); + if (!offset_pointer) { + result = MBFL_ERROR_OFFSET; goto out; } - result = (size_t) -1; + result = MBFL_ERROR_NOT_FOUND; if (haystack_u8->len < needle_u8->len) { goto out; } + const char *found_pos; if (!reverse) { - size_t jtbl[1 << (sizeof(unsigned char) * 8)]; - size_t needle_u8_len = needle_u8->len; - size_t i; - const unsigned char *p, *q, *e; - const unsigned char *haystack_u8_val = haystack_u8->val, - *needle_u8_val = needle_u8->val; - for (i = 0; i < sizeof(jtbl) / sizeof(*jtbl); ++i) { - jtbl[i] = needle_u8_len + 1; - } - for (i = 0; i < needle_u8_len - 1; ++i) { - jtbl[needle_u8_val[i]] = needle_u8_len - i; - } - e = haystack_u8_val + haystack_u8->len; - p = haystack_u8_val; - while (offset-- > 0) { - if (p >= e) { - result = (size_t) -16; - goto out; - } - p += u8_tbl[*p]; - } - p += needle_u8_len; - if (p > e) { - goto out; - } - while (p <= e) { - const unsigned char *pv = p; - q = needle_u8_val + needle_u8_len; - for (;;) { - if (q == needle_u8_val) { - result = 0; - while (p > haystack_u8_val) { - unsigned char c = *--p; - if (c < 0x80) { - ++result; - } else if ((c & 0xc0) != 0x80) { - ++result; - } - } - goto out; - } - if (*--q != *--p) { - break; - } - } - p += jtbl[*p]; - if (p <= pv) { - p = pv + 1; - } - } + found_pos = zend_memnstr( + (const char *) offset_pointer, + (const char *) needle_u8->val, needle_u8->len, + (const char *) haystack_u8->val + haystack_u8->len); } else { - size_t jtbl[1 << (sizeof(unsigned char) * 8)]; - size_t needle_u8_len = needle_u8->len, needle_len = 0; - size_t i; - const unsigned char *p, *e, *q, *qe; - const unsigned char *haystack_u8_val = haystack_u8->val, - *needle_u8_val = needle_u8->val; - for (i = 0; i < sizeof(jtbl) / sizeof(*jtbl); ++i) { - jtbl[i] = needle_u8_len; - } - for (i = needle_u8_len - 1; i > 0; --i) { - unsigned char c = needle_u8_val[i]; - jtbl[c] = i; - if (c < 0x80) { - ++needle_len; - } else if ((c & 0xc0) != 0x80) { - ++needle_len; - } - } - { - unsigned char c = needle_u8_val[0]; - if (c < 0x80) { - ++needle_len; - } else if ((c & 0xc0) != 0x80) { - ++needle_len; - } - } - e = haystack_u8_val; - p = e + haystack_u8->len; - qe = needle_u8_val + needle_u8_len; - if (offset < 0) { - if (-offset > needle_len) { - offset += needle_len; - while (offset < 0) { - unsigned char c; - if (p <= e) { - result = (size_t) -16; - goto out; - } - c = *(--p); - if (c < 0x80) { - ++offset; - } else if ((c & 0xc0) != 0x80) { - ++offset; - } - } - } + if (offset >= 0) { + found_pos = zend_memnrstr( + (const char *) offset_pointer, + (const char *) needle_u8->val, needle_u8->len, + (const char *) haystack_u8->val + haystack_u8->len); } else { - const unsigned char *ee = haystack_u8_val + haystack_u8->len; - while (offset-- > 0) { - if (e >= ee) { - result = (size_t) -16; - goto out; - } - e += u8_tbl[*e]; - } - } - if (p < e + needle_u8_len) { - goto out; - } - p -= needle_u8_len; - while (p >= e) { - const unsigned char *pv = p; - q = needle_u8_val; - for (;;) { - if (q == qe) { - result = 0; - p -= needle_u8_len; - while (p > haystack_u8_val) { - unsigned char c = *--p; - if (c < 0x80) { - ++result; - } else if ((c & 0xc0) != 0x80) { - ++result; - } - } - goto out; - } - if (*q != *p) { - break; - } - ++p, ++q; - } - p -= jtbl[*p]; - if (p >= pv) { - p = pv - 1; + size_t needle_len = mbfl_strlen(needle_u8); + offset_pointer = mbfl_find_offset_utf8( + offset_pointer, haystack_u8->val + haystack_u8->len, needle_len); + if (!offset_pointer) { + offset_pointer = haystack_u8->val + haystack_u8->len; } + + found_pos = zend_memnrstr( + (const char *) haystack_u8->val, + (const char *) needle_u8->val, needle_u8->len, + (const char *) offset_pointer); } } + + if (found_pos) { + result = mbfl_pointer_to_offset_utf8(haystack_u8->val, (const unsigned char *) found_pos); + } + out: if (haystack_u8 == &_haystack_u8) { mbfl_string_clear(&_haystack_u8); @@ -1031,9 +938,6 @@ mbfl_substr_count( mbfl_convert_filter *filter; struct collector_strpos_data pc; - if (haystack == NULL || needle == NULL) { - return (size_t) -8; - } /* needle is converted into wchar */ mbfl_wchar_device_init(&pc.needle); filter = mbfl_convert_filter_new( @@ -1041,18 +945,18 @@ mbfl_substr_count( &mbfl_encoding_wchar, mbfl_wchar_device_output, 0, &pc.needle); if (filter == NULL) { - return (size_t) -4; + return MBFL_ERROR_ENCODING; } mbfl_convert_filter_feed_string(filter, needle->val, needle->len); mbfl_convert_filter_flush(filter); mbfl_convert_filter_delete(filter); pc.needle_len = pc.needle.pos; if (pc.needle.buffer == NULL) { - return (size_t) -4; + return MBFL_ERROR_ENCODING; } - if (pc.needle_len <= 0) { + if (pc.needle_len == 0) { mbfl_wchar_device_clear(&pc.needle); - return (size_t) -2; + return MBFL_ERROR_EMPTY; } /* initialize filter and collector data */ filter = mbfl_convert_filter_new( @@ -1061,13 +965,13 @@ mbfl_substr_count( collector_strpos, 0, &pc); if (filter == NULL) { mbfl_wchar_device_clear(&pc.needle); - return (size_t) -4; + return MBFL_ERROR_ENCODING; } pc.start = 0; pc.output = 0; pc.needle_pos = 0; pc.found_pos = 0; - pc.matched_pos = (size_t) -1; + pc.matched_pos = MBFL_ERROR_NOT_FOUND; /* feed data */ p = haystack->val; @@ -1075,12 +979,12 @@ mbfl_substr_count( if (p != NULL) { while (n > 0) { if ((*filter->filter_function)(*p++, filter) < 0) { - pc.matched_pos = (size_t) -4; + pc.matched_pos = MBFL_ERROR_ENCODING; break; } - if (pc.matched_pos != (size_t) -1) { + if (pc.matched_pos != MBFL_ERROR_NOT_FOUND) { ++result; - pc.matched_pos = (size_t) -1; + pc.matched_pos = MBFL_ERROR_NOT_FOUND; pc.needle_pos = 0; } n--; @@ -1134,7 +1038,6 @@ mbfl_substr( unsigned char *p, *w; mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; if ((encoding->flag & (MBFL_ENCTYPE_SBCS | MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE | MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) || @@ -1206,13 +1109,9 @@ mbfl_substr( n = end - start; result->len = 0; result->val = w = (unsigned char*)mbfl_malloc(n + 1); - if (w != NULL) { - result->len = n; - memcpy(w, string->val + start, n); - w[n] = '\0'; - } else { - result = NULL; - } + result->len = n; + memcpy(w, string->val + start, n); + w[n] = '\0'; } else { mbfl_memory_device device; struct collector_substr_data pc; @@ -1225,7 +1124,6 @@ mbfl_substr( mbfl_memory_device_init(&device, length + 1, 0); mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; /* output code filter */ decoder = mbfl_convert_filter_new( @@ -1287,7 +1185,6 @@ mbfl_strcut( } mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; if ((encoding->flag & (MBFL_ENCTYPE_SBCS @@ -1359,10 +1256,7 @@ mbfl_strcut( /* allocate memory and copy string */ sz = end - start; - if ((w = (unsigned char*)mbfl_calloc(sz + 8, - sizeof(unsigned char))) == NULL) { - return NULL; - } + w = mbfl_calloc(sz + 8, sizeof(unsigned char)); memcpy(w, start, sz); w[sz] = '\0'; @@ -1676,7 +1570,6 @@ mbfl_strimwidth( return NULL; } mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; mbfl_memory_device_init(&pc.device, MIN(string->len, width), 0); @@ -1782,7 +1675,6 @@ mbfl_ja_jp_hantozen( mbfl_memory_device_init(&device, string->len, 0); mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; decoder = mbfl_convert_filter_new( @@ -1794,12 +1686,7 @@ mbfl_ja_jp_hantozen( } next_filter = decoder; - param = - (mbfl_filt_tl_jisx0201_jisx0208_param *)mbfl_malloc(sizeof(mbfl_filt_tl_jisx0201_jisx0208_param)); - if (param == NULL) { - goto out; - } - + param = mbfl_malloc(sizeof(mbfl_filt_tl_jisx0201_jisx0208_param)); param->mode = mode; tl_filter = mbfl_convert_filter_new2( @@ -2035,11 +1922,7 @@ mime_header_encoder_new( return NULL; } - pe = (struct mime_header_encoder_data*)mbfl_malloc(sizeof(struct mime_header_encoder_data)); - if (pe == NULL) { - return NULL; - } - + pe = mbfl_malloc(sizeof(struct mime_header_encoder_data)); mbfl_memory_device_init(&pe->outdev, 0, 0); mbfl_memory_device_init(&pe->tmpdev, 0, 0); pe->prevpos = 0; @@ -2144,7 +2027,6 @@ mbfl_mime_header_encode( struct mime_header_encoder_data *pe; mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = &mbfl_encoding_ascii; pe = mime_header_encoder_new(string->encoding, outcode, encoding); @@ -2383,12 +2265,7 @@ mime_header_decoder_result(struct mime_header_decoder_data *pd, mbfl_string *res struct mime_header_decoder_data* mime_header_decoder_new(const mbfl_encoding *outcode) { - struct mime_header_decoder_data *pd; - - pd = (struct mime_header_decoder_data*)mbfl_malloc(sizeof(struct mime_header_decoder_data)); - if (pd == NULL) { - return NULL; - } + struct mime_header_decoder_data *pd = mbfl_malloc(sizeof(struct mime_header_decoder_data)); mbfl_memory_device_init(&pd->outdev, 0, 0); mbfl_memory_device_init(&pd->tmpdev, 0, 0); @@ -2441,7 +2318,6 @@ mbfl_mime_header_decode( struct mime_header_decoder_data *pd; mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = outcode; pd = mime_header_decoder_new(outcode); @@ -2836,7 +2712,6 @@ mbfl_html_numeric_entity( return NULL; } mbfl_string_init(result); - result->no_language = string->no_language; result->encoding = string->encoding; mbfl_memory_device_init(&device, string->len, 0); diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.h b/ext/mbstring/libmbfl/mbfl/mbfilter.h index 0966e2df44..ba5f6b1df7 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.h +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.h @@ -193,7 +193,7 @@ static inline int mbfl_is_error(size_t len) { * strlen */ MBFLAPI extern size_t -mbfl_strlen(mbfl_string *string); +mbfl_strlen(const mbfl_string *string); /* * oddlen @@ -201,8 +201,14 @@ mbfl_strlen(mbfl_string *string); MBFLAPI extern size_t mbfl_oddlen(mbfl_string *string); +#define MBFL_ERROR_NOT_FOUND ((size_t) -1) +#define MBFL_ERROR_ENCODING ((size_t) -4) +#define MBFL_ERROR_EMPTY ((size_t) -8) +#define MBFL_ERROR_OFFSET ((size_t) -16) + /* - * strpos + * strpos. + * Errors: MBFL_ERROR_NOT_FOUND, MBFL_ERROR_ENCODING, MBFL_ERROR_OFFSET */ MBFLAPI extern size_t mbfl_strpos(mbfl_string *haystack, mbfl_string *needle, ssize_t offset, int reverse); diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c index a6a4e9f01f..98c9644f9d 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter_8bit.c @@ -60,7 +60,8 @@ const struct mbfl_convert_vtbl vtbl_8bit_wchar = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_8bit_wchar, - mbfl_filt_conv_common_flush + mbfl_filt_conv_common_flush, + NULL, }; const struct mbfl_convert_vtbl vtbl_wchar_8bit = { @@ -69,7 +70,8 @@ const struct mbfl_convert_vtbl vtbl_wchar_8bit = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_wchar_8bit, - mbfl_filt_conv_common_flush + mbfl_filt_conv_common_flush, + NULL, }; #define CK(statement) do { if ((statement) < 0) return (-1); } while (0) diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter_pass.c b/ext/mbstring/libmbfl/mbfl/mbfilter_pass.c index 343a968794..34543786d8 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter_pass.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter_pass.c @@ -55,7 +55,8 @@ const struct mbfl_convert_vtbl vtbl_pass = { mbfl_filt_conv_common_ctor, mbfl_filt_conv_common_dtor, mbfl_filt_conv_pass, - mbfl_filt_conv_common_flush + mbfl_filt_conv_common_flush, + NULL, }; int mbfl_filt_conv_pass(int c, mbfl_convert_filter *filter) diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_allocators.c b/ext/mbstring/libmbfl/mbfl/mbfl_allocators.c index 42130e8b2c..dbc4fc71ca 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_allocators.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_allocators.c @@ -48,9 +48,6 @@ static mbfl_allocators default_allocators = { __mbfl__realloc, __mbfl__calloc, __mbfl__free, - __mbfl__malloc, - __mbfl__realloc, - __mbfl__free }; mbfl_allocators *__mbfl_allocators = &default_allocators; diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_allocators.h b/ext/mbstring/libmbfl/mbfl/mbfl_allocators.h index 08fc275d04..cc341d464a 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_allocators.h +++ b/ext/mbstring/libmbfl/mbfl/mbfl_allocators.h @@ -34,14 +34,14 @@ #include <stddef.h> #include "mbfl_defs.h" +/* All allocation functions are required to be infallible. + * That is, they must never return NULL. */ + typedef struct _mbfl_allocators { void *(*malloc)(size_t); void *(*realloc)(void *, size_t); void *(*calloc)(size_t, size_t); void (*free)(void *); - void *(*pmalloc)(size_t); - void *(*prealloc)(void *, size_t); - void (*pfree)(void *); } mbfl_allocators; MBFLAPI extern mbfl_allocators *__mbfl_allocators; @@ -50,8 +50,5 @@ MBFLAPI extern mbfl_allocators *__mbfl_allocators; #define mbfl_realloc (__mbfl_allocators->realloc) #define mbfl_calloc (__mbfl_allocators->calloc) #define mbfl_free (__mbfl_allocators->free) -#define mbfl_pmalloc (__mbfl_allocators->pmalloc) -#define mbfl_prealloc (__mbfl_allocators->preallloc) -#define mbfl_pfree (__mbfl_allocators->pfree) #endif /* MBFL_ALLOCATORS_H */ diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c index 04e0a13de9..98f2cee048 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_convert.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_convert.c @@ -165,7 +165,7 @@ mbfl_convert_filter_new( int (*flush_function)(void*), void* data) { - mbfl_convert_filter * filter; + mbfl_convert_filter *filter; const struct mbfl_convert_vtbl *vtbl; vtbl = mbfl_convert_filter_get_vtbl(from, to); @@ -173,11 +173,7 @@ mbfl_convert_filter_new( return NULL; } - /* allocate */ - filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter)); - if (filter == NULL) { - return NULL; - } + filter = mbfl_malloc(sizeof(mbfl_convert_filter)); if (mbfl_convert_filter_common_init(filter, from, to, vtbl, output_function, flush_function, data)) { @@ -195,7 +191,7 @@ mbfl_convert_filter_new2( int (*flush_function)(void*), void* data) { - mbfl_convert_filter * filter; + mbfl_convert_filter *filter; const mbfl_encoding *from_encoding, *to_encoding; if (vtbl == NULL) { @@ -205,11 +201,7 @@ mbfl_convert_filter_new2( from_encoding = mbfl_no2encoding(vtbl->from); to_encoding = mbfl_no2encoding(vtbl->to); - /* allocate */ - filter = (mbfl_convert_filter *)mbfl_malloc(sizeof(mbfl_convert_filter)); - if (filter == NULL) { - return NULL; - } + filter = mbfl_malloc(sizeof(mbfl_convert_filter)); if (mbfl_convert_filter_common_init(filter, from_encoding, to_encoding, vtbl, output_function, flush_function, data)) { diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c index be861629d0..4feaadd542 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c @@ -115,7 +115,6 @@ static const mbfl_encoding *mbfl_encoding_ptr_list[] = { - &mbfl_encoding_pass, &mbfl_encoding_wchar, &mbfl_encoding_byte2be, &mbfl_encoding_byte2le, diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_ident.c b/ext/mbstring/libmbfl/mbfl/mbfl_ident.c index ce7cf13566..be49c64543 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_ident.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_ident.c @@ -191,14 +191,7 @@ const struct mbfl_identify_vtbl * mbfl_identify_filter_get_vtbl(enum mbfl_no_enc mbfl_identify_filter *mbfl_identify_filter_new(enum mbfl_no_encoding encoding) { - mbfl_identify_filter *filter; - - /* allocate */ - filter = (mbfl_identify_filter *)mbfl_malloc(sizeof(mbfl_identify_filter)); - if (filter == NULL) { - return NULL; - } - + mbfl_identify_filter *filter = mbfl_malloc(sizeof(mbfl_identify_filter)); if (mbfl_identify_filter_init(filter, encoding)) { mbfl_free(filter); return NULL; @@ -209,14 +202,7 @@ mbfl_identify_filter *mbfl_identify_filter_new(enum mbfl_no_encoding encoding) mbfl_identify_filter *mbfl_identify_filter_new2(const mbfl_encoding *encoding) { - mbfl_identify_filter *filter; - - /* allocate */ - filter = (mbfl_identify_filter *)mbfl_malloc(sizeof(mbfl_identify_filter)); - if (filter == NULL) { - return NULL; - } - + mbfl_identify_filter *filter = mbfl_malloc(sizeof(mbfl_identify_filter)); if (mbfl_identify_filter_init2(filter, encoding)) { mbfl_free(filter); return NULL; diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c b/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c index 0dd8ea2e66..27d3ef2fac 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_memory_device.c @@ -49,10 +49,8 @@ mbfl_memory_device_init(mbfl_memory_device *device, size_t initsz, size_t allocs device->length = 0; device->buffer = NULL; if (initsz > 0) { - device->buffer = (unsigned char *)mbfl_malloc(initsz); - if (device->buffer != NULL) { - device->length = initsz; - } + device->buffer = mbfl_malloc(initsz); + device->length = initsz; } device->pos = 0; if (allocsz > MBFL_MEMORY_DEVICE_ALLOC_SIZE) { @@ -66,15 +64,10 @@ mbfl_memory_device_init(mbfl_memory_device *device, size_t initsz, size_t allocs void mbfl_memory_device_realloc(mbfl_memory_device *device, size_t initsz, size_t allocsz) { - unsigned char *tmp; - if (device) { if (initsz > device->length) { - tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, initsz); - if (tmp != NULL) { - device->buffer = tmp; - device->length = initsz; - } + device->buffer = mbfl_realloc(device->buffer, initsz); + device->length = initsz; } if (allocsz > MBFL_MEMORY_DEVICE_ALLOC_SIZE) { device->allocsz = allocsz; @@ -142,7 +135,6 @@ mbfl_memory_device_output(int c, void *data) if (device->pos >= device->length) { /* reallocate buffer */ size_t newlen; - unsigned char *tmp; if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ @@ -150,12 +142,8 @@ mbfl_memory_device_output(int c, void *data) } newlen = device->length + device->allocsz; - tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen); - if (tmp == NULL) { - return -1; - } + device->buffer = mbfl_realloc(device->buffer, newlen); device->length = newlen; - device->buffer = tmp; } device->buffer[device->pos++] = (unsigned char)c; @@ -170,7 +158,6 @@ mbfl_memory_device_output2(int c, void *data) if (2 > device->length - device->pos) { /* reallocate buffer */ size_t newlen; - unsigned char *tmp; if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ @@ -178,12 +165,8 @@ mbfl_memory_device_output2(int c, void *data) } newlen = device->length + device->allocsz; - tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen); - if (tmp == NULL) { - return -1; - } + device->buffer = mbfl_realloc(device->buffer, newlen); device->length = newlen; - device->buffer = tmp; } device->buffer[device->pos++] = (unsigned char)((c >> 8) & 0xff); @@ -200,7 +183,6 @@ mbfl_memory_device_output4(int c, void* data) if (4 > device->length - device->pos) { /* reallocate buffer */ size_t newlen; - unsigned char *tmp; if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ @@ -208,12 +190,8 @@ mbfl_memory_device_output4(int c, void* data) } newlen = device->length + device->allocsz; - tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen); - if (tmp == NULL) { - return -1; - } + device->buffer = mbfl_realloc(device->buffer, newlen); device->length = newlen; - device->buffer = tmp; } device->buffer[device->pos++] = (unsigned char)((c >> 24) & 0xff); @@ -238,7 +216,6 @@ mbfl_memory_device_strncat(mbfl_memory_device *device, const char *psrc, size_t if (len > device->length - device->pos) { /* reallocate buffer */ size_t newlen; - unsigned char *tmp; if (len > SIZE_MAX - MBFL_MEMORY_DEVICE_ALLOC_SIZE || device->length > SIZE_MAX - (len + MBFL_MEMORY_DEVICE_ALLOC_SIZE)) { @@ -247,13 +224,8 @@ mbfl_memory_device_strncat(mbfl_memory_device *device, const char *psrc, size_t } newlen = device->length + len + MBFL_MEMORY_DEVICE_ALLOC_SIZE; - tmp = (unsigned char *)mbfl_realloc((void *)device->buffer, newlen); - if (tmp == NULL) { - return -1; - } - + device->buffer = mbfl_realloc(device->buffer, newlen); device->length = newlen; - device->buffer = tmp; } w = &device->buffer[device->pos]; @@ -301,7 +273,6 @@ mbfl_wchar_device_output(int c, void *data) if (device->pos >= device->length) { /* reallocate buffer */ size_t newlen; - unsigned int *tmp; if (device->length > SIZE_MAX - device->allocsz) { /* overflow */ @@ -314,12 +285,8 @@ mbfl_wchar_device_output(int c, void *data) return -1; } - tmp = (unsigned int *)mbfl_realloc((void *)device->buffer, newlen*sizeof(int)); - if (tmp == NULL) { - return -1; - } + device->buffer = mbfl_realloc(device->buffer, newlen*sizeof(int)); device->length = newlen; - device->buffer = tmp; } device->buffer[device->pos++] = c; diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_string.c b/ext/mbstring/libmbfl/mbfl/mbfl_string.c index b1acecb259..fc9f211092 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_string.c +++ b/ext/mbstring/libmbfl/mbfl/mbfl_string.c @@ -44,33 +44,25 @@ void mbfl_string_init(mbfl_string *string) { - if (string) { - string->no_language = mbfl_no_language_uni; - string->encoding = &mbfl_encoding_pass; - string->val = (unsigned char*)NULL; - string->len = 0; - } + string->encoding = &mbfl_encoding_pass; + string->val = (unsigned char*)NULL; + string->len = 0; } void -mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, const mbfl_encoding *encoding) +mbfl_string_init_set(mbfl_string *string, const mbfl_encoding *encoding) { - if (string) { - string->no_language = no_language; - string->encoding = encoding; - string->val = (unsigned char*)NULL; - string->len = 0; - } + string->encoding = encoding; + string->val = (unsigned char*)NULL; + string->len = 0; } void mbfl_string_clear(mbfl_string *string) { - if (string) { - if (string->val != (unsigned char*)NULL) { - mbfl_free(string->val); - } - string->val = (unsigned char*)NULL; - string->len = 0; + if (string->val != (unsigned char*)NULL) { + mbfl_free(string->val); } + string->val = (unsigned char*)NULL; + string->len = 0; } diff --git a/ext/mbstring/libmbfl/mbfl/mbfl_string.h b/ext/mbstring/libmbfl/mbfl/mbfl_string.h index 43f4a5fa75..d96a77cca7 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfl_string.h +++ b/ext/mbstring/libmbfl/mbfl/mbfl_string.h @@ -40,14 +40,13 @@ * string object */ typedef struct _mbfl_string { - enum mbfl_no_language no_language; const mbfl_encoding *encoding; unsigned char *val; size_t len; } mbfl_string; MBFLAPI extern void mbfl_string_init(mbfl_string *string); -MBFLAPI extern void mbfl_string_init_set(mbfl_string *string, mbfl_language_id no_language, const mbfl_encoding *encoding); +MBFLAPI extern void mbfl_string_init_set(mbfl_string *string, const mbfl_encoding *encoding); MBFLAPI extern void mbfl_string_clear(mbfl_string *string); #ifndef NULL |