<commit_before>#include "ua_list.h"
#include "ua_util.h"

void UA_list_defaultFreer(void* payload){
	if(payload){
		UA_free(payload);
	}
}

UA_Int32 UA_list_initElement(UA_list_Element* element){
	if(element==UA_NULL) return UA_ERROR;
	element->next=UA_NULL;
	element->prev=UA_NULL;
	element->father=UA_NULL;
	element->payload=UA_NULL;
	return UA_NO_ERROR;
}

UA_Int32 UA_list_init(UA_list_List* list){
	if(list==UA_NULL) return UA_ERROR;
	list->first = UA_NULL;
	list->last = UA_NULL;
	list->size = 0;
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element){
	if(list==UA_NULL || element==UA_NULL) return UA_ERROR;
	UA_list_Element* second = UA_NULL;
	second = list->first;
	list->first = element;
	element->prev = UA_NULL;
	element->next = second;
	element->father = list;
	if(second){
		second->prev=element;
	}
	list->size++;
	if(list->size==1){
		list->last=element;
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* elem;
	UA_alloc((void**)&elem, sizeof(*elem));
	UA_list_initElement(elem);
	elem->payload = payload;
	UA_list_addElementToFront(list, elem);
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element){
	if(list==UA_NULL || element == UA_NULL)return UA_ERROR;
	UA_list_Element* secondLast = UA_NULL;
	secondLast = list->last;
	list->last = element;
	element->prev = secondLast;
	element->next = UA_NULL;
	element->father = list;
	if(secondLast){
		secondLast->next = element;
	}
	list->size++;
	if(list->size==1){
		list->first=element;
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* elem;
	UA_alloc((void**)&elem, sizeof(*elem));
	UA_list_initElement(elem);
	elem->payload = payload;
	UA_list_addElementToBack(list, elem);
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* temp = UA_NULL;
	if(list->first){
		temp = list->first->next;
		if(visitor){
			(*visitor)(list->first->payload);
		}
		UA_free(list->first);
		list->first = temp;
		if(temp){
			temp->prev = UA_NULL;
		}
		list->size--;
		if(list->size == 1){
			list->last = temp;
		}else if(list->size==0){
			list->last = UA_NULL;
		}
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* temp = UA_NULL;
	if(list->last){
		temp = list->last->prev;
		if(visitor){
			(*visitor)(list->last->payload);
		}
		UA_free(list->last);
		list->last = temp;
		if(temp){
			temp->next = UA_NULL;
		}
		list->size--;
		if(list->size == 1){
			list->first = temp;
			list->first->next = UA_NULL;
		}else if(list->size==0){
			list->first = UA_NULL;
		}
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor){
	if(elem==UA_NULL)return UA_ERROR;
	if(elem==elem->father->first){
		return UA_list_removeFirst(elem->father, visitor);
	}else if(elem==elem->father->last){
		return UA_list_removeLast(elem->father, visitor);
	}else{
		UA_list_Element* prev = elem->prev;
		UA_list_Element* next = elem->next;
		prev->next = next;
		next->prev = prev;
		if(visitor){
			(*visitor)(elem->payload);
		}<commit_msg>fixed coverity warning message (ua_list_removeLast, null pointer derefencing)<commit_after>#include "ua_list.h"
#include "ua_util.h"

void UA_list_defaultFreer(void* payload){
	if(payload){
		UA_free(payload);
	}
}

UA_Int32 UA_list_initElement(UA_list_Element* element){
	if(element==UA_NULL) return UA_ERROR;
	element->next=UA_NULL;
	element->prev=UA_NULL;
	element->father=UA_NULL;
	element->payload=UA_NULL;
	return UA_NO_ERROR;
}

UA_Int32 UA_list_init(UA_list_List* list){
	if(list==UA_NULL) return UA_ERROR;
	list->first = UA_NULL;
	list->last = UA_NULL;
	list->size = 0;
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element){
	if(list==UA_NULL || element==UA_NULL) return UA_ERROR;
	UA_list_Element* second = UA_NULL;
	second = list->first;
	list->first = element;
	element->prev = UA_NULL;
	element->next = second;
	element->father = list;
	if(second){
		second->prev=element;
	}
	list->size++;
	if(list->size==1){
		list->last=element;
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* elem;
	UA_alloc((void**)&elem, sizeof(*elem));
	UA_list_initElement(elem);
	elem->payload = payload;
	UA_list_addElementToFront(list, elem);
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element){
	if(list==UA_NULL || element == UA_NULL)return UA_ERROR;
	UA_list_Element* secondLast = UA_NULL;
	secondLast = list->last;
	list->last = element;
	element->prev = secondLast;
	element->next = UA_NULL;
	element->father = list;
	if(secondLast){
		secondLast->next = element;
	}
	list->size++;
	if(list->size==1){
		list->first=element;
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* elem;
	UA_alloc((void**)&elem, sizeof(*elem));
	UA_list_initElement(elem);
	elem->payload = payload;
	UA_list_addElementToBack(list, elem);
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* temp = UA_NULL;
	if(list->first){
		temp = list->first->next;
		if(visitor){
			(*visitor)(list->first->payload);
		}
		UA_free(list->first);
		list->first = temp;
		if(temp){
			temp->prev = UA_NULL;
		}
		list->size--;
		if(list->size == 1){
			list->last = temp;
		}else if(list->size==0){
			list->last = UA_NULL;
		}
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor){
	if(list==UA_NULL)return UA_ERROR;
	UA_list_Element* temp = UA_NULL;
	if(list->last){
		temp = list->last->prev;
		if(visitor){
			(*visitor)(list->last->payload);
		}
		UA_free(list->last);
		list->last = temp;
		if(temp){
			temp->next = UA_NULL;
		}
		list->size--;
		if(list->size == 1){
			list->first = temp;
		}else if(list->size==0){
			list->first = UA_NULL;
		}
	}
	return UA_NO_ERROR;
}

UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor){
	if(elem==UA_NULL)return UA_ERROR;
	if(elem==elem->father->first){
		return UA_list_removeFirst(elem->father, visitor);
	}else if(elem==elem->father->last){
		return UA_list_removeLast(elem->father, visitor);
	}else{
		UA_list_Element* prev = elem->prev;
		UA_list_Element* next = elem->next;
		prev->next = next;
		next->prev = prev;
		if(visitor){
			(*visitor)(elem->payload);
		}
{'fraction_non_alphanumeric': 0.15253018976423233, 'fraction_numerical': 0.00718803910293272, 'mean_word_length': 5.453617810760668, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393693', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2817, 'n_words': 461}