mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-18 10:15:13 +00:00
Fix double-iteration in curl_slist_remove (#1951)
Also backfill tests. Fixes #1948.
This commit is contained in:
parent
92fd5bc3e1
commit
904682b856
@ -109,7 +109,7 @@ struct curl_slist* curl_slist_remove(struct curl_slist* list, const char* key)
|
||||
|
||||
std::string strkey = trim(std::string(key));
|
||||
struct curl_slist **p = &list;
|
||||
for(;*p; p = &(*p)->next){
|
||||
while(*p){
|
||||
std::string strcur = (*p)->data;
|
||||
size_t pos;
|
||||
if(std::string::npos != (pos = strcur.find(':', 0))){
|
||||
@ -122,6 +122,8 @@ struct curl_slist* curl_slist_remove(struct curl_slist* list, const char* key)
|
||||
struct curl_slist *tmp = *p;
|
||||
*p = (*p)->next;
|
||||
free(tmp);
|
||||
}else{
|
||||
p = &(*p)->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,9 +105,55 @@ void test_sort_insert()
|
||||
curl_slist_free_all(list);
|
||||
}
|
||||
|
||||
void test_slist_remove()
|
||||
{
|
||||
struct curl_slist* list = NULL;
|
||||
|
||||
// remove no elements
|
||||
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
|
||||
list = curl_slist_remove(list, "1");
|
||||
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
|
||||
|
||||
// remove only element
|
||||
list = NULL;
|
||||
list = curl_slist_sort_insert(list, "1", "val");
|
||||
ASSERT_EQUALS(static_cast<size_t>(1), curl_slist_length(list));
|
||||
list = curl_slist_remove(list, "1");
|
||||
ASSERT_EQUALS(static_cast<size_t>(0), curl_slist_length(list));
|
||||
|
||||
// remove head element
|
||||
list = NULL;
|
||||
list = curl_slist_sort_insert(list, "1", "val");
|
||||
list = curl_slist_sort_insert(list, "2", "val");
|
||||
ASSERT_EQUALS(static_cast<size_t>(2), curl_slist_length(list));
|
||||
list = curl_slist_remove(list, "1");
|
||||
ASSERT_EQUALS(static_cast<size_t>(1), curl_slist_length(list));
|
||||
curl_slist_free_all(list);
|
||||
|
||||
// remove tail element
|
||||
list = NULL;
|
||||
list = curl_slist_sort_insert(list, "1", "val");
|
||||
list = curl_slist_sort_insert(list, "2", "val");
|
||||
ASSERT_EQUALS(static_cast<size_t>(2), curl_slist_length(list));
|
||||
list = curl_slist_remove(list, "2");
|
||||
ASSERT_EQUALS(static_cast<size_t>(1), curl_slist_length(list));
|
||||
curl_slist_free_all(list);
|
||||
|
||||
// remove middle element
|
||||
list = NULL;
|
||||
list = curl_slist_sort_insert(list, "1", "val");
|
||||
list = curl_slist_sort_insert(list, "2", "val");
|
||||
list = curl_slist_sort_insert(list, "3", "val");
|
||||
ASSERT_EQUALS(static_cast<size_t>(3), curl_slist_length(list));
|
||||
list = curl_slist_remove(list, "2");
|
||||
ASSERT_EQUALS(static_cast<size_t>(2), curl_slist_length(list));
|
||||
curl_slist_free_all(list);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
test_sort_insert();
|
||||
test_slist_remove();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user