@@ -4123,7 +4123,7 @@ PHP_FUNCTION(imap_mime_header_decode)
4123
4123
static long _php_rfc822_soutr (void * stream , char * string )
4124
4124
{
4125
4125
smart_str * ret = (smart_str * )stream ;
4126
- int len = strlen (string );
4126
+ size_t len = strlen (string );
4127
4127
4128
4128
smart_str_appendl (ret , string , len );
4129
4129
return LONGT ;
@@ -4151,63 +4151,55 @@ static zend_string* _php_rfc822_write_address(ADDRESS *addresslist)
4151
4151
4152
4152
#else
4153
4153
4154
- /* {{{ _php_rfc822_len
4155
- * Calculate string length based on imap's rfc822_cat function.
4156
- */
4157
- static int _php_rfc822_len (char * str )
4154
+ /* Calculate string length based on imap's rfc822_cat function. */
4155
+ static size_t _php_rfc822_len (const char * const str )
4158
4156
{
4159
- int len ;
4160
- char * p ;
4161
-
4157
+ /* Non existent or empty string */
4162
4158
if (!str || !* str ) {
4163
4159
return 0 ;
4164
4160
}
4165
4161
4166
4162
/* strings with special characters will need to be quoted, as a safety measure we
4167
4163
* add 2 bytes for the quotes just in case.
4168
4164
*/
4169
- len = strlen (str ) + 2 ;
4170
- p = str ;
4165
+ size_t len = strlen (str ) + 2 ;
4166
+
4171
4167
/* rfc822_cat() will escape all " and \ characters, therefore we need to increase
4172
4168
* our buffer length to account for these characters.
4173
4169
*/
4170
+ const char * p = str ;
4174
4171
while ((p = strpbrk (p , "\\\"" ))) {
4175
4172
p ++ ;
4176
4173
len ++ ;
4177
4174
}
4178
4175
4179
4176
return len ;
4180
4177
}
4181
- /* }}} */
4182
4178
4183
- /* {{{ _php_imap_get_address_size */
4184
- static int _php_imap_address_size (ADDRESS * addresslist )
4179
+ static size_t _php_imap_address_size (const ADDRESS * const address_list )
4185
4180
{
4186
- ADDRESS * tmp ;
4187
- int ret = 0 , num_ent = 0 ;
4188
-
4189
- tmp = addresslist ;
4181
+ size_t total_size = 0 ;
4182
+ unsigned int nb_addresses = 0 ;
4183
+ const ADDRESS * current_address = address_list ;
4190
4184
4191
- if (tmp ) do {
4192
- ret += _php_rfc822_len (tmp -> personal );
4193
- ret += _php_rfc822_len (tmp -> adl );
4194
- ret += _php_rfc822_len (tmp -> mailbox );
4195
- ret += _php_rfc822_len (tmp -> host );
4196
- num_ent ++ ;
4197
- } while ((tmp = tmp -> next ));
4185
+ if (current_address ) do {
4186
+ total_size += _php_rfc822_len (current_address -> personal );
4187
+ total_size += _php_rfc822_len (current_address -> adl );
4188
+ total_size += _php_rfc822_len (current_address -> mailbox );
4189
+ total_size += _php_rfc822_len (current_address -> host );
4190
+ nb_addresses ++ ;
4191
+ } while ((current_address = current_address -> next ));
4198
4192
4199
4193
/*
4200
4194
* rfc822_write_address_full() needs some extra space for '<>,', etc.
4201
- * for this perpouse we allocate additional PHP_IMAP_ADDRESS_SIZE_BUF bytes
4195
+ * for this purpose we allocate additional PHP_IMAP_ADDRESS_SIZE_BUF bytes
4202
4196
* by default this buffer is 10 bytes long
4203
- */
4204
- ret += ( ret ) ? num_ent * PHP_IMAP_ADDRESS_SIZE_BUF : 0 ;
4197
+ */
4198
+ total_size += nb_addresses * PHP_IMAP_ADDRESS_SIZE_BUF ;
4205
4199
4206
- return ret ;
4200
+ return total_size ;
4207
4201
}
4208
4202
4209
- /* }}} */
4210
-
4211
4203
/* {{{ _php_rfc822_write_address */
4212
4204
static zend_string * _php_rfc822_write_address (ADDRESS * addresslist )
4213
4205
{
0 commit comments