@@ -2158,10 +2158,8 @@ static int exif_file_sections_realloc(image_info_type *ImageInfo, int section_in
2158
2158
*/
2159
2159
static void exif_file_sections_free (image_info_type * ImageInfo )
2160
2160
{
2161
- int i ;
2162
-
2163
2161
if (ImageInfo -> file .count ) {
2164
- for (i = 0 ; i < ImageInfo -> file .count ; i ++ ) {
2162
+ for (int i = 0 ; i < ImageInfo -> file .count ; i ++ ) {
2165
2163
EFREE_IF (ImageInfo -> file .list [i ].data );
2166
2164
}
2167
2165
}
@@ -2403,11 +2401,10 @@ static void exif_iif_add_buffer(image_info_type *image_info, int section_index,
2403
2401
Free memory allocated for image_info
2404
2402
*/
2405
2403
static void exif_iif_free (image_info_type * image_info , int section_index ) {
2406
- int i ;
2407
2404
void * f ; /* faster */
2408
2405
2409
2406
if (image_info -> info_list [section_index ].count ) {
2410
- for (i = 0 ; i < image_info -> info_list [section_index ].count ; i ++ ) {
2407
+ for (int i = 0 ; i < image_info -> info_list [section_index ].count ; i ++ ) {
2411
2408
if ((f = image_info -> info_list [section_index ].list [i ].name ) != NULL ) {
2412
2409
efree (f );
2413
2410
}
@@ -2448,7 +2445,6 @@ static void exif_iif_free(image_info_type *image_info, int section_index) {
2448
2445
* Add image_info to associative array value. */
2449
2446
static void add_assoc_image_info (zval * value , int sub_array , image_info_type * image_info , int section_index )
2450
2447
{
2451
- char buffer [64 ], uname [64 ];
2452
2448
int idx = 0 , unknown = 0 ;
2453
2449
2454
2450
if (!image_info -> info_list [section_index ].count ) {
@@ -2466,6 +2462,8 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im
2466
2462
image_info_data * info_data = & image_info -> info_list [section_index ].list [i ];
2467
2463
image_info_value * info_value = & info_data -> value ;
2468
2464
const char * name = info_data -> name ;
2465
+ char uname [64 ];
2466
+
2469
2467
if (!name ) {
2470
2468
snprintf (uname , sizeof (uname ), "%d" , unknown ++ );
2471
2469
name = uname ;
@@ -2516,6 +2514,7 @@ static void add_assoc_image_info(zval *value, int sub_array, image_info_type *im
2516
2514
array_init (& array );
2517
2515
}
2518
2516
for (int ap = 0 ; ap < l ; ap ++ ) {
2517
+ char buffer [64 ];
2519
2518
if (l > 1 ) {
2520
2519
info_value = & info_data -> value .list [ap ];
2521
2520
}
@@ -2785,8 +2784,7 @@ PHP_FUNCTION(exif_tagname)
2785
2784
* Create a value for an ifd from an info_data pointer */
2786
2785
static void * exif_ifd_make_value (image_info_data * info_data , int motorola_intel ) {
2787
2786
size_t byte_count ;
2788
- char * value_ptr , * data_ptr ;
2789
- size_t i ;
2787
+ char * value_ptr ;
2790
2788
2791
2789
image_info_value * info_value ;
2792
2790
@@ -2808,8 +2806,8 @@ static void* exif_ifd_make_value(image_info_data *info_data, int motorola_intel)
2808
2806
* value_ptr = info_data -> value .i ;
2809
2807
return value_ptr ;
2810
2808
} else {
2811
- data_ptr = value_ptr ;
2812
- for (i = 0 ; i < info_data -> length ; i ++ ) {
2809
+ char * data_ptr = value_ptr ;
2810
+ for (size_t i = 0 ; i < info_data -> length ; i ++ ) {
2813
2811
if (info_data -> length == 1 ) {
2814
2812
info_value = & info_data -> value ;
2815
2813
} else {
@@ -3032,15 +3030,14 @@ static int exif_process_string(char **result, const char *value, size_t byte_cou
3032
3030
* Process UserComment in IFD. */
3033
3031
static int exif_process_user_comment (const image_info_type * ImageInfo , char * * pszInfoPtr , char * * pszEncoding , char * szValuePtr , int ByteCount )
3034
3032
{
3035
- int a ;
3036
- char * decode ;
3037
3033
size_t len ;
3038
3034
3039
3035
* pszEncoding = NULL ;
3040
3036
/* Copy the comment */
3041
3037
if (ByteCount >=8 ) {
3042
3038
const zend_encoding * from , * to ;
3043
3039
if (!memcmp (szValuePtr , "UNICODE\0" , 8 )) {
3040
+ char * decode ;
3044
3041
* pszEncoding = estrdup (szValuePtr );
3045
3042
szValuePtr = szValuePtr + 8 ;
3046
3043
ByteCount -= 8 ;
@@ -3105,7 +3102,7 @@ static int exif_process_user_comment(const image_info_type *ImageInfo, char **ps
3105
3102
3106
3103
/* Olympus has this padded with trailing spaces. Remove these first. */
3107
3104
if (ByteCount > 0 ) {
3108
- for (a = ByteCount - 1 ;a && szValuePtr [a ]== ' ' ;a -- ) {
3105
+ for (int a = ByteCount - 1 ; a && szValuePtr [a ]== ' ' ; a -- ) {
3109
3106
(szValuePtr )[a ] = '\0' ;
3110
3107
}
3111
3108
}
@@ -3141,14 +3138,13 @@ static int exif_process_unicode(const image_info_type *ImageInfo, xp_field_type
3141
3138
* Process nested IFDs directories in Maker Note. */
3142
3139
static bool exif_process_IFD_in_MAKERNOTE (image_info_type * ImageInfo , char * value_ptr , int value_len , const exif_offset_info * info , size_t displacement )
3143
3140
{
3144
- size_t i ;
3145
- int de , section_index = SECTION_MAKERNOTE ;
3141
+ int section_index = SECTION_MAKERNOTE ;
3146
3142
int NumDirEntries , old_motorola_intel ;
3147
3143
const maker_note_type * maker_note ;
3148
3144
char * dir_start ;
3149
3145
exif_offset_info new_info ;
3150
3146
3151
- for (i = 0 ; i <= sizeof (maker_note_array )/sizeof (maker_note_type ); i ++ ) {
3147
+ for (size_t i = 0 ; i <= sizeof (maker_note_array )/sizeof (maker_note_type ); i ++ ) {
3152
3148
if (i == sizeof (maker_note_array )/sizeof (maker_note_type )) {
3153
3149
#ifdef EXIF_DEBUG
3154
3150
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_NOTICE , "No maker note data found. Detected maker: %s (length = %d)" , ImageInfo -> make , ImageInfo -> make ? strlen (ImageInfo -> make ) : 0 );
@@ -3229,7 +3225,7 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
3229
3225
break ;
3230
3226
}
3231
3227
3232
- for (de = 0 ; de < NumDirEntries ;de ++ ) {
3228
+ for (int de = 0 ; de < NumDirEntries ; de ++ ) {
3233
3229
size_t offset = 2 + 12 * de ;
3234
3230
if (!exif_process_IFD_TAG (ImageInfo , dir_start + offset ,
3235
3231
info , displacement , section_index , 0 , maker_note -> tag_table )) {
@@ -3257,16 +3253,10 @@ static bool exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * val
3257
3253
* Process one of the nested IFDs directories. */
3258
3254
static bool exif_process_IFD_TAG_impl (image_info_type * ImageInfo , char * dir_entry , const exif_offset_info * info , size_t displacement , int section_index , int ReadNextIFD , tag_table_type tag_table )
3259
3255
{
3260
- size_t length ;
3261
3256
unsigned int tag , format , components ;
3262
3257
char * value_ptr , tagname [64 ], cbuf [32 ], * outside = NULL ;
3263
- size_t byte_count , offset_val , fpos , fgot ;
3258
+ size_t byte_count , offset_val ;
3264
3259
int64_t byte_count_signed ;
3265
- xp_field_type * tmp_xp ;
3266
- #ifdef EXIF_DEBUG
3267
- char * dump_data ;
3268
- int dump_free ;
3269
- #endif /* EXIF_DEBUG */
3270
3260
3271
3261
tag = php_ifd_get16u (dir_entry , ImageInfo -> motorola_intel );
3272
3262
format = php_ifd_get16u (dir_entry + 2 , ImageInfo -> motorola_intel );
@@ -3314,9 +3304,9 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
3314
3304
value_ptr = cbuf ;
3315
3305
}
3316
3306
3317
- fpos = php_stream_tell (ImageInfo -> infile );
3307
+ size_t fpos = php_stream_tell (ImageInfo -> infile );
3318
3308
php_stream_seek (ImageInfo -> infile , displacement + offset_val , SEEK_SET );
3319
- fgot = php_stream_tell (ImageInfo -> infile );
3309
+ size_t fgot = php_stream_tell (ImageInfo -> infile );
3320
3310
if (fgot != displacement + offset_val ) {
3321
3311
EFREE_IF (outside );
3322
3312
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_WARNING , "Wrong file pointer: 0x%08X != 0x%08X" , fgot , displacement + offset_val );
@@ -3339,7 +3329,8 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
3339
3329
3340
3330
ImageInfo -> sections_found |= FOUND_ANY_TAG ;
3341
3331
#ifdef EXIF_DEBUG
3342
- dump_data = exif_dump_data (& dump_free , format , components , ImageInfo -> motorola_intel , value_ptr );
3332
+ int dump_free ;
3333
+ char * dump_data = exif_dump_data (& dump_free , format , components , ImageInfo -> motorola_intel , value_ptr );
3343
3334
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_NOTICE ,
3344
3335
"Process tag(x%04X=%s,@0x%04X + x%04X(=%d)): %s%s %s" ,
3345
3336
tag , exif_get_tagname_debug (tag , tag_table ), offset_val + displacement , byte_count , byte_count , (components > 1 )&& format != TAG_FMT_UNDEFINED && format != TAG_FMT_STRING ?"ARRAY OF " :"" , exif_get_tagformat (format ), dump_data );
@@ -3392,7 +3383,8 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
3392
3383
} else {
3393
3384
if (section_index == SECTION_IFD0 || section_index == SECTION_EXIF )
3394
3385
switch (tag ) {
3395
- case TAG_COPYRIGHT :
3386
+ case TAG_COPYRIGHT : {
3387
+ size_t length ;
3396
3388
/* check for "<photographer> NUL <editor> NUL" */
3397
3389
if (byte_count > 1 && (length = zend_strnlen (value_ptr , byte_count )) > 0 ) {
3398
3390
if (length < byte_count - 1 ) {
@@ -3412,6 +3404,7 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
3412
3404
}
3413
3405
}
3414
3406
break ;
3407
+ }
3415
3408
3416
3409
case TAG_USERCOMMENT :
3417
3410
EFREE_IF (ImageInfo -> UserComment );
@@ -3425,13 +3418,14 @@ static bool exif_process_IFD_TAG_impl(image_info_type *ImageInfo, char *dir_entr
3425
3418
case TAG_XP_COMMENTS :
3426
3419
case TAG_XP_AUTHOR :
3427
3420
case TAG_XP_KEYWORDS :
3428
- case TAG_XP_SUBJECT :
3429
- tmp_xp = (xp_field_type * )safe_erealloc (ImageInfo -> xp_fields .list , (ImageInfo -> xp_fields .count + 1 ), sizeof (xp_field_type ), 0 );
3421
+ case TAG_XP_SUBJECT : {
3422
+ xp_field_type * tmp_xp = (xp_field_type * )safe_erealloc (ImageInfo -> xp_fields .list , (ImageInfo -> xp_fields .count + 1 ), sizeof (xp_field_type ), 0 );
3430
3423
ImageInfo -> sections_found |= FOUND_WINXP ;
3431
3424
ImageInfo -> xp_fields .list = tmp_xp ;
3432
3425
ImageInfo -> xp_fields .count ++ ;
3433
3426
exif_process_unicode (ImageInfo , & (ImageInfo -> xp_fields .list [ImageInfo -> xp_fields .count - 1 ]), tag , value_ptr , byte_count );
3434
3427
break ;
3428
+ }
3435
3429
3436
3430
case TAG_FNUMBER :
3437
3431
/* Simplest way of expressing aperture, so I trust it the most.
@@ -4032,7 +4026,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir
4032
4026
{
4033
4027
int i , sn , num_entries , sub_section_index = 0 ;
4034
4028
unsigned char * dir_entry ;
4035
- size_t ifd_size , dir_size , entry_offset , next_offset , entry_length , entry_value = 0 , fgot ;
4029
+ size_t ifd_size , dir_size , next_offset , entry_length , entry_value = 0 ;
4036
4030
int entry_tag , entry_type ;
4037
4031
tag_table_type tag_table = exif_get_tag_table (section_index );
4038
4032
@@ -4119,7 +4113,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir
4119
4113
break ;
4120
4114
}
4121
4115
} else {
4122
- entry_offset = php_ifd_get32u (dir_entry + 8 , ImageInfo -> motorola_intel );
4116
+ size_t entry_offset = php_ifd_get32u (dir_entry + 8 , ImageInfo -> motorola_intel );
4123
4117
/* if entry needs expanding ifd cache and entry is at end of current ifd cache. */
4124
4118
/* otherwise there may be huge holes between two entries */
4125
4119
if (entry_offset + entry_length > dir_offset + ifd_size
@@ -4178,7 +4172,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir
4178
4172
sub_section_index = SECTION_THUMBNAIL ;
4179
4173
break ;
4180
4174
}
4181
- entry_offset = php_ifd_get32u (dir_entry + 8 , ImageInfo -> motorola_intel );
4175
+ size_t entry_offset = php_ifd_get32u (dir_entry + 8 , ImageInfo -> motorola_intel );
4182
4176
#ifdef EXIF_DEBUG
4183
4177
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_NOTICE , "Next IFD: %s @0x%04X" , exif_get_sectionname (sub_section_index ), entry_offset );
4184
4178
#endif
@@ -4195,7 +4189,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir
4195
4189
if (!ImageInfo -> Thumbnail .data ) {
4196
4190
ImageInfo -> Thumbnail .data = safe_emalloc (ImageInfo -> Thumbnail .size , 1 , 0 );
4197
4191
php_stream_seek (ImageInfo -> infile , ImageInfo -> Thumbnail .offset , SEEK_SET );
4198
- fgot = exif_read_from_stream_file_looped (ImageInfo -> infile , ImageInfo -> Thumbnail .data , ImageInfo -> Thumbnail .size );
4192
+ size_t fgot = exif_read_from_stream_file_looped (ImageInfo -> infile , ImageInfo -> Thumbnail .data , ImageInfo -> Thumbnail .size );
4199
4193
if (fgot != ImageInfo -> Thumbnail .size ) {
4200
4194
EXIF_ERRLOG_THUMBEOF (ImageInfo )
4201
4195
efree (ImageInfo -> Thumbnail .data );
@@ -4235,7 +4229,7 @@ static bool exif_process_IFD_in_TIFF_impl(image_info_type *ImageInfo, size_t dir
4235
4229
if (!ImageInfo -> Thumbnail .data && ImageInfo -> Thumbnail .offset && ImageInfo -> Thumbnail .size && ImageInfo -> read_thumbnail ) {
4236
4230
ImageInfo -> Thumbnail .data = safe_emalloc (ImageInfo -> Thumbnail .size , 1 , 0 );
4237
4231
php_stream_seek (ImageInfo -> infile , ImageInfo -> Thumbnail .offset , SEEK_SET );
4238
- fgot = exif_read_from_stream_file_looped (ImageInfo -> infile , ImageInfo -> Thumbnail .data , ImageInfo -> Thumbnail .size );
4232
+ size_t fgot = exif_read_from_stream_file_looped (ImageInfo -> infile , ImageInfo -> Thumbnail .data , ImageInfo -> Thumbnail .size );
4239
4233
if (fgot != ImageInfo -> Thumbnail .size ) {
4240
4234
EXIF_ERRLOG_THUMBEOF (ImageInfo )
4241
4235
efree (ImageInfo -> Thumbnail .data );
@@ -4494,7 +4488,7 @@ PHP_FUNCTION(exif_read_data)
4494
4488
bool ret ;
4495
4489
int i , sections_needed = 0 ;
4496
4490
image_info_type ImageInfo ;
4497
- char tmp [ 64 ], * sections_str , * s ;
4491
+ char * sections_str ;
4498
4492
4499
4493
/* Parse arguments */
4500
4494
ZEND_PARSE_PARAMETERS_START (1 , 4 )
@@ -4510,14 +4504,15 @@ PHP_FUNCTION(exif_read_data)
4510
4504
if (z_sections_needed ) {
4511
4505
spprintf (& sections_str , 0 , ",%s ,", ZSTR_VAL (z_sections_needed ));
4512
4506
/* sections_str DOES start with , and SPACES are NOT allowed in names */
4513
- s = sections_str ;
4507
+ char * s = sections_str ;
4514
4508
while (* ++ s ) {
4515
4509
if (* s == ' ' ) {
4516
4510
* s = ',' ;
4517
4511
}
4518
4512
}
4519
4513
4520
4514
for (i = 0 ; i < SECTION_COUNT ; i ++ ) {
4515
+ char tmp [64 ];
4521
4516
snprintf (tmp , sizeof (tmp ), ",%s," , exif_get_sectionname (i ));
4522
4517
if (strstr (sections_str , tmp )) {
4523
4518
sections_needed |= 1 <<i ;
0 commit comments