1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-11-08 22:31:31 +01:00

fix: correct usage of malloc and sizeof for structs

This commit is contained in:
Théo LUDWIG 2023-08-09 20:25:03 +02:00
parent 6505e3ba49
commit f99e4941e4
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
3 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);