From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im, shejialuo@gmail.com
Subject: Re: [PATCH v3 3/8] reftable: check for trailing newline in 'tables.list'
Date: Thu, 18 Sep 2025 08:36:07 -0700 [thread overview]
Message-ID: <xmqqo6r793iw.fsf@gitster.g> (raw)
In-Reply-To: <20250918-228-reftable-introduce-consistency-checks-v3-3-271af03eb34d@gmail.com> (Karthik Nayak's message of "Thu, 18 Sep 2025 10:11:44 +0200")
Karthik Nayak <karthik.188@gmail.com> writes:
> diff --git a/reftable/basics.h b/reftable/basics.h
> index 7d22f96261..019dfe6d7e 100644
> --- a/reftable/basics.h
> +++ b/reftable/basics.h
> @@ -167,10 +167,11 @@ void free_names(char **a);
>
> /*
> * Parse a newline separated list of names. `size` is the length of the buffer,
> - * without terminating '\0'. Empty names are discarded. Returns a `NULL`
> - * pointer when allocations fail.
> + * without terminating '\0'. Empty names are discarded.
> + *
> + * Errors are assigned to the `err` variable.
> */
> -char **parse_names(char *buf, int size);
> +char **parse_names(char *buf, int size, int *err);
>
> /* compares two NULL-terminated arrays of strings. */
> int names_equal(const char **a, const char **b);
Makes sense.
> diff --git a/reftable/stack.c b/reftable/stack.c
> index f91ce50bcd..955be1edb6 100644
> --- a/reftable/stack.c
> +++ b/reftable/stack.c
> @@ -109,11 +109,9 @@ static int fd_read_lines(int fd, char ***namesp)
> }
> buf[size] = 0;
>
> - *namesp = parse_names(buf, size);
> - if (!*namesp) {
> - err = REFTABLE_OUT_OF_MEMORY_ERROR;
> + *namesp = parse_names(buf, size, &err);
> + if (!*namesp)
> goto done;
Nice.
> diff --git a/t/unit-tests/u-reftable-basics.c b/t/unit-tests/u-reftable-basics.c
> index a0471083e7..f77ec96429 100644
> --- a/t/unit-tests/u-reftable-basics.c
> +++ b/t/unit-tests/u-reftable-basics.c
> @@ -9,6 +9,7 @@ license that can be found in the LICENSE file or at
> #include "unit-test.h"
> #include "lib-reftable.h"
> #include "reftable/basics.h"
> +#include "reftable/reftable-error.h"
>
> struct integer_needle_lesseq_args {
> int needle;
> @@ -79,14 +80,17 @@ void test_reftable_basics__names_equal(void)
> void test_reftable_basics__parse_names(void)
> {
> char in1[] = "line\n";
> - char in2[] = "a\nb\nc";
> - char **out = parse_names(in1, strlen(in1));
> + char in2[] = "a\nb\nc\n";
> + int err = 0;
> + char **out = parse_names(in1, strlen(in1), &err);
> + cl_assert(err == 0);
> cl_assert(out != NULL);
> cl_assert_equal_s(out[0], "line");
> cl_assert(!out[1]);
> free_names(out);
>
> - out = parse_names(in2, strlen(in2));
> + out = parse_names(in2, strlen(in2), &err);
> + cl_assert(err == 0);
> cl_assert(out != NULL);
> cl_assert_equal_s(out[0], "a");
> cl_assert_equal_s(out[1], "b");
Sensible.
> @@ -95,10 +99,21 @@ void test_reftable_basics__parse_names(void)
> free_names(out);
> }
>
> +void test_reftable_basics__parse_names_missing_newline(void)
> +{
> + char in1[] = "line\nline2";
> + int err = 0;
> + char **out = parse_names(in1, strlen(in1), &err);
> + cl_assert(err == REFTABLE_FORMAT_ERROR);
> + cl_assert(out == NULL);
> +}
OK.
> void test_reftable_basics__parse_names_drop_empty_string(void)
> {
> char in[] = "a\n\nb\n";
> - char **out = parse_names(in, strlen(in));
> + int err = 0;
> + char **out = parse_names(in, strlen(in), &err);
> + cl_assert(err == 0);
I'll drop an extra SP after == here (no need to resend only to fix
this).
> cl_assert(out != NULL);
> cl_assert_equal_s(out[0], "a");
> /* simply '\n' should be dropped as empty string */
next prev parent reply other threads:[~2025-09-18 15:36 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-19 12:20 [PATCH 0/5] refs/reftable: add fsck checks Karthik Nayak
2025-08-19 12:21 ` [PATCH 1/5] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-08-19 12:21 ` [PATCH 2/5] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-08-26 16:21 ` shejialuo
2025-09-01 13:33 ` Karthik Nayak
2025-09-03 13:39 ` shejialuo
2025-08-19 12:21 ` [PATCH 3/5] refs/reftable: add fsck check for number of tables Karthik Nayak
2025-08-26 16:33 ` shejialuo
2025-09-01 13:40 ` Karthik Nayak
2025-08-26 16:44 ` shejialuo
2025-09-01 13:52 ` Karthik Nayak
2025-08-19 12:21 ` [PATCH 4/5] refs/reftable: add fsck check for trailing newline Karthik Nayak
2025-08-19 12:21 ` [PATCH 5/5] refs/reftable: add fsck check for incorrect update index Karthik Nayak
2025-08-26 16:39 ` [PATCH 0/5] refs/reftable: add fsck checks shejialuo
2025-09-01 13:52 ` Karthik Nayak
2025-09-02 7:05 ` [PATCH v2 " Karthik Nayak
2025-09-02 7:05 ` [PATCH v2 1/5] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-09-02 22:25 ` Junio C Hamano
2025-09-08 13:00 ` Karthik Nayak
2025-09-02 7:05 ` [PATCH v2 2/5] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-09-03 8:07 ` Patrick Steinhardt
2025-09-03 16:51 ` shejialuo
2025-09-09 13:49 ` Karthik Nayak
2025-09-09 8:42 ` Karthik Nayak
2025-09-02 7:05 ` [PATCH v2 3/5] refs/reftable: add fsck check for number of tables Karthik Nayak
2025-09-03 8:07 ` Patrick Steinhardt
2025-09-15 9:27 ` Karthik Nayak
2025-09-02 7:05 ` [PATCH v2 4/5] refs/reftable: add fsck check for trailing newline Karthik Nayak
2025-09-02 22:38 ` Junio C Hamano
2025-09-03 8:07 ` Patrick Steinhardt
2025-09-02 7:05 ` [PATCH v2 5/5] refs/reftable: add fsck check for incorrect update index Karthik Nayak
2025-09-02 22:42 ` Junio C Hamano
2025-09-18 8:11 ` Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 0/8] refs/reftable: add consistency checks Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 1/8] refs: remove unused headers Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 2/8] refs: move consistency check msg to generic layer Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 3/8] reftable: check for trailing newline in 'tables.list' Karthik Nayak
2025-09-18 15:36 ` Junio C Hamano [this message]
2025-09-23 15:42 ` Karthik Nayak
2025-09-24 5:54 ` Patrick Steinhardt
2025-09-24 10:02 ` Karthik Nayak
2025-09-24 7:24 ` Kristoffer Haugsbakk
2025-09-24 11:06 ` Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 4/8] reftable: ensure tables in a stack use sequential update indices Karthik Nayak
2025-09-24 5:54 ` Patrick Steinhardt
2025-09-24 11:20 ` Karthik Nayak
2025-09-24 18:04 ` Junio C Hamano
2025-09-24 20:13 ` Karthik Nayak
2025-09-25 6:12 ` Patrick Steinhardt
2025-09-25 16:22 ` Junio C Hamano
2025-09-18 8:11 ` [PATCH v3 5/8] Documentation/fsck-msgids: remove duplicate msg id Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 6/8] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-09-18 8:11 ` [PATCH v3 7/8] reftable: add code to facilitate consistency checks Karthik Nayak
2025-09-24 5:54 ` Patrick Steinhardt
2025-09-24 18:40 ` Karthik Nayak
2025-09-25 6:14 ` Patrick Steinhardt
2025-09-18 8:11 ` [PATCH v3 8/8] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-09-24 5:54 ` Patrick Steinhardt
2025-09-24 18:44 ` Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 0/7] refs/reftable: add consistency checks Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 1/7] refs: remove unused headers Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 2/7] refs: move consistency check msg to generic layer Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 3/7] reftable: check for trailing newline in 'tables.list' Karthik Nayak
2025-10-02 11:44 ` Patrick Steinhardt
2025-10-06 12:02 ` Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 4/7] Documentation/fsck-msgids: remove duplicate msg id Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 5/7] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-09-26 7:25 ` [PATCH v4 6/7] reftable: add code to facilitate consistency checks Karthik Nayak
2025-10-02 11:44 ` Patrick Steinhardt
2025-09-26 7:25 ` [PATCH v4 7/7] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-10-02 11:44 ` Patrick Steinhardt
2025-10-06 12:05 ` Karthik Nayak
2025-09-26 21:08 ` [PATCH v4 0/7] refs/reftable: add consistency checks Junio C Hamano
2025-10-06 14:22 ` [PATCH v5 " Karthik Nayak
2025-10-06 14:22 ` [PATCH v5 1/7] refs: remove unused headers Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 2/7] refs: move consistency check msg to generic layer Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 3/7] reftable: check for trailing newline in 'tables.list' Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 4/7] Documentation/fsck-msgids: remove duplicate msg id Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 5/7] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 6/7] reftable: add code to facilitate consistency checks Karthik Nayak
2025-10-06 14:23 ` [PATCH v5 7/7] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-10-07 2:32 ` Jeff King
2025-10-07 8:45 ` Karthik Nayak
2025-10-06 22:08 ` [PATCH v5 0/7] refs/reftable: add consistency checks Junio C Hamano
2025-10-07 8:47 ` Karthik Nayak
2025-10-07 15:11 ` Junio C Hamano
2025-10-07 12:11 ` [PATCH v6 " Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 1/7] refs: remove unused headers Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 2/7] refs: move consistency check msg to generic layer Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 3/7] reftable: check for trailing newline in 'tables.list' Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 4/7] Documentation/fsck-msgids: remove duplicate msg id Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 5/7] fsck: order 'fsck_msg_type' alphabetically Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 6/7] reftable: add code to facilitate consistency checks Karthik Nayak
2025-10-07 12:11 ` [PATCH v6 7/7] refs/reftable: add fsck check for checking the table name Karthik Nayak
2025-10-07 13:26 ` [PATCH v6 0/7] refs/reftable: add consistency checks Patrick Steinhardt
2025-10-07 16:25 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqo6r793iw.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=ps@pks.im \
--cc=shejialuo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).