mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-12-11 21:13:00 +01:00
fix: correct usage of malloc and sizeof for structs
This commit is contained in:
parent
6505e3ba49
commit
f99e4941e4
@ -1,7 +1,7 @@
|
||||
#include "linked_list.h"
|
||||
|
||||
struct linked_list *linked_list_initialization() {
|
||||
struct linked_list *list = malloc(sizeof(*list));
|
||||
struct linked_list *list = malloc(sizeof(struct linked_list));
|
||||
if (list == NULL) {
|
||||
perror("Error (linked_list_initialization)");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -17,7 +17,7 @@ struct linked_list_node *linked_list_add_in_head(struct linked_list *list, void
|
||||
perror("Error (linked_list_add_in_head)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct linked_list_node *node_new = malloc(sizeof(*node_new));
|
||||
struct linked_list_node *node_new = malloc(sizeof(struct linked_list_node));
|
||||
if (node_new == NULL) {
|
||||
perror("Error (linked_list_add_in_head)");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -52,7 +52,7 @@ struct linked_list_node *linked_list_add_after_last(struct linked_list *list, vo
|
||||
if (list->head == NULL) {
|
||||
return linked_list_add_in_head(list, new_data);
|
||||
}
|
||||
struct linked_list_node *node_new = malloc(sizeof(*node_new));
|
||||
struct linked_list_node *node_new = malloc(sizeof(struct linked_list_node));
|
||||
if (node_new == NULL) {
|
||||
perror("Error (linked_list_add_after_last)");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "queue.h"
|
||||
|
||||
struct queue *queue_initialization() {
|
||||
struct queue *queue = malloc(sizeof(*queue));
|
||||
struct queue *queue = malloc(sizeof(struct queue));
|
||||
if (queue == NULL) {
|
||||
perror("Error (queue_initialization)");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -17,7 +17,7 @@ void queue_push(struct queue *queue, void *data) {
|
||||
perror("Error (queue_push)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct queue_node *node_new = malloc(sizeof(*node_new));
|
||||
struct queue_node *node_new = malloc(sizeof(struct queue_node));
|
||||
if (node_new == NULL) {
|
||||
perror("Error (queue_push)");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "stack.h"
|
||||
|
||||
struct stack *stack_initialization() {
|
||||
struct stack *stack = malloc(sizeof(*stack));
|
||||
struct stack *stack = malloc(sizeof(struct stack));
|
||||
if (stack == NULL) {
|
||||
perror("Error (stack_initialization)");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -17,7 +17,7 @@ void stack_push(struct stack *stack, void *data) {
|
||||
perror("Error (stack_push)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct stack_node *node_new = malloc(sizeof(*node_new));
|
||||
struct stack_node *node_new = malloc(sizeof(struct stack_node));
|
||||
if (data == NULL) {
|
||||
perror("Error (stack_push)");
|
||||
exit(EXIT_FAILURE);
|
||||
|
Loading…
Reference in New Issue
Block a user