Skip to content

Commit ed9c0bb

Browse files
committed
exif: remove local php_strnlen, use zend_strnlen instead
1 parent 43cff80 commit ed9c0bb

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

ext/exif/exif.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,6 @@ static ssize_t exif_read_from_stream_file_looped(php_stream *stream, char *buf,
234234
return total_read;
235235
}
236236

237-
/* {{{ php_strnlen
238-
* get length of string if buffer if less than buffer size or buffer size */
239-
static size_t php_strnlen(char* str, size_t maxlen) {
240-
size_t len = 0;
241-
242-
if (str && maxlen && *str) {
243-
do {
244-
len++;
245-
} while (--maxlen && *(++str));
246-
}
247-
return len;
248-
}
249237
/* }}} */
250238

251239
/* {{{ error messages */
@@ -2223,7 +2211,7 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
22232211
value = NULL;
22242212
}
22252213
if (value) {
2226-
length = (int)php_strnlen(value, length);
2214+
length = (int)zend_strnlen(value, length);
22272215
info_value->s = estrndup(value, length);
22282216
info_data->length = length;
22292217
} else {
@@ -2254,7 +2242,7 @@ static void exif_iif_add_value(image_info_type *image_info, int section_index, c
22542242
}
22552243
if (value) {
22562244
if (tag == TAG_MAKER_NOTE) {
2257-
length = (int) php_strnlen(value, length);
2245+
length = (int) zend_strnlen(value, length);
22582246
}
22592247

22602248
/* do not recompute length here */
@@ -3034,11 +3022,11 @@ static int exif_process_string(char **result, char *value, size_t byte_count) {
30343022
/* we cannot use strlcpy - here the problem is that we cannot use strlen to
30353023
* determine length of string and we cannot use strlcpy with len=byte_count+1
30363024
* because then we might get into an EXCEPTION if we exceed an allocated
3037-
* memory page...so we use php_strnlen in conjunction with memcpy and add the NUL
3025+
* memory page...so we use zend_strnlen in conjunction with memcpy and add the NUL
30383026
* char.
30393027
* estrdup would sometimes allocate more memory and does not return length
30403028
*/
3041-
if ((byte_count=php_strnlen(value, byte_count)) > 0) {
3029+
if ((byte_count=zend_strnlen(value, byte_count)) > 0) {
30423030
return exif_process_undefined(result, value, byte_count);
30433031
}
30443032
(*result) = estrndup("", 1); /* force empty string */
@@ -3412,7 +3400,7 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
34123400
switch(tag) {
34133401
case TAG_COPYRIGHT:
34143402
/* check for "<photographer> NUL <editor> NUL" */
3415-
if (byte_count>1 && (length=php_strnlen(value_ptr, byte_count)) > 0) {
3403+
if (byte_count>1 && (length=zend_strnlen(value_ptr, byte_count)) > 0) {
34163404
if (length<byte_count-1) {
34173405
/* When there are any characters after the first NUL */
34183406
EFREE_IF(ImageInfo->CopyrightPhotographer);
@@ -3776,10 +3764,10 @@ static void exif_process_APP12(image_info_type *ImageInfo, char *buffer, size_t
37763764
{
37773765
size_t l1, l2=0;
37783766

3779-
if ((l1 = php_strnlen(buffer+2, length-2)) > 0) {
3767+
if ((l1 = zend_strnlen(buffer+2, length-2)) > 0) {
37803768
exif_iif_add_tag(ImageInfo, SECTION_APP12, "Company", TAG_NONE, TAG_FMT_STRING, l1, buffer+2, l1);
37813769
if (length > 2+l1+1) {
3782-
l2 = php_strnlen(buffer+2+l1+1, length-2-l1-1);
3770+
l2 = zend_strnlen(buffer+2+l1+1, length-2-l1-1);
37833771
exif_iif_add_tag(ImageInfo, SECTION_APP12, "Info", TAG_NONE, TAG_FMT_STRING, l2, buffer+2+l1+1, l2);
37843772
}
37853773
}

0 commit comments

Comments
 (0)