Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
anchitj committed Jun 4, 2024
1 parent b45c353 commit 7c01770
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/rdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 1 addition & 5 deletions src/rdbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
28 changes: 14 additions & 14 deletions tests/0011-produce_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ 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();

msgid_next = 0;

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);
Expand All @@ -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));
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 7c01770

Please sign in to comment.