@@ -4123,7 +4123,7 @@ PHP_FUNCTION(imap_mime_header_decode)
41234123static long _php_rfc822_soutr (void * stream , char * string )
41244124{
41254125 smart_str * ret = (smart_str * )stream ;
4126- int len = strlen (string );
4126+ size_t len = strlen (string );
41274127
41284128 smart_str_appendl (ret , string , len );
41294129 return LONGT ;
@@ -4151,63 +4151,55 @@ static zend_string* _php_rfc822_write_address(ADDRESS *addresslist)
41514151
41524152#else
41534153
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 )
41584156{
4159- int len ;
4160- char * p ;
4161-
4157+ /* Non existent or empty string */
41624158 if (!str || !* str ) {
41634159 return 0 ;
41644160 }
41654161
41664162 /* strings with special characters will need to be quoted, as a safety measure we
41674163 * add 2 bytes for the quotes just in case.
41684164 */
4169- len = strlen (str ) + 2 ;
4170- p = str ;
4165+ size_t len = strlen (str ) + 2 ;
4166+
41714167 /* rfc822_cat() will escape all " and \ characters, therefore we need to increase
41724168 * our buffer length to account for these characters.
41734169 */
4170+ const char * p = str ;
41744171 while ((p = strpbrk (p , "\\\"" ))) {
41754172 p ++ ;
41764173 len ++ ;
41774174 }
41784175
41794176 return len ;
41804177}
4181- /* }}} */
41824178
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 )
41854180{
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 ;
41904184
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 ));
41984192
41994193 /*
42004194 * 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
42024196 * 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 ;
42054199
4206- return ret ;
4200+ return total_size ;
42074201}
42084202
4209- /* }}} */
4210-
42114203/* {{{ _php_rfc822_write_address */
42124204static zend_string * _php_rfc822_write_address (ADDRESS * addresslist )
42134205{
0 commit comments