From 7c017706c9ff8b7b72bf8fe3d1b7732a13192ef3 Mon Sep 17 00:00:00 2001 From: Anchit Jain Date: Wed, 15 May 2024 11:26:27 +0530 Subject: [PATCH] PR Feedback --- src/rdbuf.c | 4 +++- src/rdbuf.h | 6 +----- tests/0011-produce_batch.c | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/rdbuf.c b/src/rdbuf.c index 6df64a9dee..88ec7912b5 100644 --- a/src/rdbuf.c +++ b/src/rdbuf.c @@ -665,8 +665,10 @@ size_t rd_buf_erase(rd_buf_t *rbuf, size_t absof, size_t size) { of += toerase; /* If segment is now empty, remove it */ - if (seg->seg_of == 0) + if (seg->seg_of == 0) { rd_buf_destroy_segment(rbuf, seg); + rbuf->rbuf_erased -= toerase; + } } /* Update absolute offset of remaining segments */ diff --git a/src/rdbuf.h b/src/rdbuf.h index a415f9d2ec..90d61401b0 100644 --- a/src/rdbuf.h +++ b/src/rdbuf.h @@ -147,11 +147,7 @@ static RD_INLINE RD_UNUSED size_t rd_buf_write_pos(const rd_buf_t *rbuf) { * @returns the number of bytes available for writing (before growing). */ static RD_INLINE RD_UNUSED size_t rd_buf_write_remains(const rd_buf_t *rbuf) { - ssize_t remaining = - rbuf->rbuf_size - (rbuf->rbuf_len + rbuf->rbuf_erased); - if (remaining < 0) - return 0; - return remaining; + return rbuf->rbuf_size - (rbuf->rbuf_len + rbuf->rbuf_erased); } diff --git a/tests/0011-produce_batch.c b/tests/0011-produce_batch.c index 13b5d22538..b73ad0345a 100644 --- a/tests/0011-produce_batch.c +++ b/tests/0011-produce_batch.c @@ -90,8 +90,8 @@ static void test_single_partition(void) { int failcnt = 0; int i; rd_kafka_message_t *rkmessages; - const int topicSuffixLength = 56, clientIdLength = 239; - char *topicSuffix, *clientId; + const int topic_suffix_length = 56, client_id_length = 239; + char *topic_suffix, *client_id; SUB_TEST_QUICK(); @@ -99,12 +99,12 @@ static void test_single_partition(void) { test_conf_init(&conf, &topic_conf, 20); - clientId = (char *)malloc(clientIdLength + 1 * sizeof(char)); - for (i = 0; i < clientIdLength; i++) { - clientId[i] = 'c'; + client_id = malloc((client_id_length + 1) * sizeof(char)); + for (i = 0; i < client_id_length; i++) { + client_id[i] = 'c'; } - clientId[clientIdLength] = '\0'; - rd_kafka_conf_set(conf, "client.id", clientId, NULL, 0); + client_id[client_id_length] = '\0'; + rd_kafka_conf_set(conf, "client.id", client_id, NULL, 0); /* Set delivery report callback */ rd_kafka_conf_set_dr_cb(conf, dr_single_partition_cb); @@ -115,13 +115,13 @@ static void test_single_partition(void) { TEST_SAY("test_single_partition: Created kafka instance %s\n", rd_kafka_name(rk)); - topicSuffix = (char *)malloc(topicSuffixLength + 1 * sizeof(char)); - for (i = 0; i < topicSuffixLength; i++) { - topicSuffix[i] = 'b'; + topic_suffix = (char *)malloc(topic_suffix_length + 1 * sizeof(char)); + for (i = 0; i < topic_suffix_length; i++) { + topic_suffix[i] = 'b'; } - topicSuffix[topicSuffixLength] = '\0'; + topic_suffix[topic_suffix_length] = '\0'; - rkt = rd_kafka_topic_new(rk, test_mk_topic_name(topicSuffix, 0), + rkt = rd_kafka_topic_new(rk, test_mk_topic_name(topic_suffix, 0), topic_conf); if (!rkt) TEST_FAIL("Failed to create topic: %s\n", rd_strerror(errno)); @@ -194,8 +194,8 @@ static void test_single_partition(void) { TEST_SAY("Destroying kafka instance %s\n", rd_kafka_name(rk)); rd_kafka_destroy(rk); - free(clientId); - free(topicSuffix); + free(client_id); + free(topic_suffix); SUB_TEST_PASS(); }