Verify memory return codes in ssh_list functions
Этот коммит содержится в:
родитель
1bea53375b
Коммит
8336c91e9c
@ -723,7 +723,7 @@ struct ssh_iterator {
|
|||||||
struct ssh_list *ssh_list_new(void);
|
struct ssh_list *ssh_list_new(void);
|
||||||
void ssh_list_free(struct ssh_list *list);
|
void ssh_list_free(struct ssh_list *list);
|
||||||
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
|
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
|
||||||
void ssh_list_add(struct ssh_list *list, const void *data);
|
int ssh_list_add(struct ssh_list *list, const void *data);
|
||||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
|
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
|
||||||
|
|
||||||
/** @brief fetch the head element of a list and remove it from list
|
/** @brief fetch the head element of a list and remove it from list
|
||||||
|
@ -152,7 +152,7 @@ const char *ssh_version(int req_version) {
|
|||||||
struct ssh_list *ssh_list_new(){
|
struct ssh_list *ssh_list_new(){
|
||||||
struct ssh_list *ret=malloc(sizeof(struct ssh_list));
|
struct ssh_list *ret=malloc(sizeof(struct ssh_list));
|
||||||
if(!ret)
|
if(!ret)
|
||||||
return ret;
|
return NULL;
|
||||||
ret->root=ret->end=NULL;
|
ret->root=ret->end=NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -174,13 +174,17 @@ struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list){
|
|||||||
|
|
||||||
static struct ssh_iterator *ssh_iterator_new(const void *data){
|
static struct ssh_iterator *ssh_iterator_new(const void *data){
|
||||||
struct ssh_iterator *iterator=malloc(sizeof(struct ssh_iterator));
|
struct ssh_iterator *iterator=malloc(sizeof(struct ssh_iterator));
|
||||||
|
if(!iterator)
|
||||||
|
return NULL;
|
||||||
iterator->next=NULL;
|
iterator->next=NULL;
|
||||||
iterator->data=data;
|
iterator->data=data;
|
||||||
return iterator;
|
return iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_list_add(struct ssh_list *list,const void *data){
|
int ssh_list_add(struct ssh_list *list,const void *data){
|
||||||
struct ssh_iterator *iterator=ssh_iterator_new(data);
|
struct ssh_iterator *iterator=ssh_iterator_new(data);
|
||||||
|
if(!iterator)
|
||||||
|
return SSH_ERROR;
|
||||||
if(!list->end){
|
if(!list->end){
|
||||||
/* list is empty */
|
/* list is empty */
|
||||||
list->root=list->end=iterator;
|
list->root=list->end=iterator;
|
||||||
@ -189,6 +193,7 @@ void ssh_list_add(struct ssh_list *list,const void *data){
|
|||||||
list->end->next=iterator;
|
list->end->next=iterator;
|
||||||
list->end=iterator;
|
list->end=iterator;
|
||||||
}
|
}
|
||||||
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
|
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user