[c] record C lists FP from #120

Summary: See https://github.com/facebook/infer/issues/120

Reviewed By: dulmarod

Differential Revision: D8443475

fbshipit-source-id: c0f76ef52
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 398e97183f
commit b23449a7d2

@ -20,6 +20,7 @@ codetoanalyze/c/errors/dangling_deref/dpd.c, nodpd1, 3, NULL_DEREFERENCE, B1
codetoanalyze/c/errors/initialization/compound_literal.c, divide_by_zero, 0, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/initialization/compound_literal.c, divide_by_zero, 0, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/initialization/initlistexpr.c, init_divide_by_zero, 2, Assert_failure, no_bucket codetoanalyze/c/errors/initialization/initlistexpr.c, init_divide_by_zero, 2, Assert_failure, no_bucket
codetoanalyze/c/errors/initialization/initlistexpr.c, init_divide_by_zero, 2, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/initialization/initlistexpr.c, init_divide_by_zero, 2, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/lists/list_api.c, FP_list_build_and_free_good, 11, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/lists/lists.c, call_delete_all2, 5, PRECONDITION_NOT_MET, no_bucket codetoanalyze/c/errors/lists/lists.c, call_delete_all2, 5, PRECONDITION_NOT_MET, no_bucket
codetoanalyze/c/errors/lists/lists.c, lists_main, 2, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/lists/lists.c, lists_main, 2, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/local_vars/local_vars.c, m1, 6, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/local_vars/local_vars.c, m1, 6, DIVIDE_BY_ZERO, no_bucket

@ -0,0 +1,73 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdlib.h>
typedef struct list_elem_s {
void* data;
struct list_elem_s* next;
} list_elem_t;
typedef struct list_s {
list_elem_t* first;
} list_t;
list_t* list_init() { return calloc(1, sizeof(list_t)); }
void list_append(list_t* lst, list_elem_t* elem) {
list_elem_t* iter;
if (NULL == lst->first) {
lst->first = elem;
} else {
iter = lst->first;
while (NULL != iter->next) {
iter = iter->next;
}
iter->next = elem;
}
}
list_elem_t* list_add(list_t* lst, void* data) {
list_elem_t* entry;
entry = calloc(1, sizeof(list_elem_t));
if (NULL == entry) {
return NULL;
}
entry->data = data;
list_append(lst, entry);
return (entry);
}
void list_elem_free(list_elem_t* ptr) {
if (NULL == ptr) {
return;
}
list_elem_free(ptr->next);
free(ptr);
}
void list_free(list_t* ptr) {
list_elem_free(ptr->first);
free(ptr);
}
int FP_list_build_and_free_good() {
int val_data = 21;
list_t* list = list_init();
if (NULL == list) {
return 1;
}
if (NULL == list_add(list, &val_data)) {
list_free(list);
return 1;
}
list_free(list);
return 0;
}
Loading…
Cancel
Save