Skip to content

Commit cbb81b8

Browse files
committed
intl: change uses of sprintf into snprintf
1 parent 934e385 commit cbb81b8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ext/intl/locale/locale_methods.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,14 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
10801080
if( cur_key_name ){
10811081
efree( cur_key_name);
10821082
}
1083-
cur_key_name = (char*)ecalloc( 25, 25);
1084-
sprintf( cur_key_name , "%s%d", key_name , cnt++);
1083+
/* Over-allocates a few bytes for the integer so we don't have to reallocate. */
1084+
size_t cur_key_name_size = (sizeof("-2147483648") - 1) + strlen(key_name) + 1;
1085+
cur_key_name = emalloc(cur_key_name_size);
1086+
snprintf( cur_key_name, cur_key_name_size , "%s%d", key_name , cnt++);
10851087
add_assoc_string( hash_arr, cur_key_name , token);
10861088
/* tokenize on the "_" or "-" and stop at singleton if any */
10871089
while( (token = php_strtok_r(NULL , DELIMITER , &last_ptr)) && (strlen(token)>1) ){
1088-
sprintf( cur_key_name , "%s%d", key_name , cnt++);
1090+
snprintf( cur_key_name , cur_key_name_size, "%s%d", key_name , cnt++);
10891091
add_assoc_string( hash_arr, cur_key_name , token);
10901092
}
10911093
/*

0 commit comments

Comments
 (0)