From 761c0194077c90c6b36df3f1eea59549a70350d0 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 10 Mar 2024 14:13:04 +0100 Subject: [PATCH] fix length difference now making a queue with size n will actually let you store n elements in it instead of n-1 --- lab01/zad1/src/main.c | 2 +- lab01/zad1/src/queue.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lab01/zad1/src/main.c b/lab01/zad1/src/main.c index 06a7a73..eaf6f02 100644 --- a/lab01/zad1/src/main.c +++ b/lab01/zad1/src/main.c @@ -7,7 +7,7 @@ int main(void) { srand((unsigned int)time(NULL)); - Queue *q = queue_new(51, sizeof(long)); + Queue *q = queue_new(50, sizeof(long)); for (size_t i = 0; i < 50; ++i) { long val = rand() % 1000; diff --git a/lab01/zad1/src/queue.c b/lab01/zad1/src/queue.c index 455441a..3e5a7bd 100644 --- a/lab01/zad1/src/queue.c +++ b/lab01/zad1/src/queue.c @@ -17,7 +17,7 @@ Queue *queue_new(size_t length, size_t element_size) { ret->front = 0; ret->length = length; ret->element_size = element_size; - ret->data = malloc(length * sizeof(void*)); + ret->data = malloc((length + 1) * sizeof(void*)); return ret; }