if to_index_str() gave you the lengh of key_str you could use add_assoc_stringl() here