git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/8] reftable: check for trailing newline in 'tables.list'

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 18, 2025, 15:36 UTC
Message-ID
<xmqqo6r793iw.fsf@gitster.g>
In-Reply-To
<20250918-228-reftable-introduce-consistency-checks-v3-3-271af03eb34d@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 19 quoted lines
> 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.
Show 14 quoted lines
> 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.
Show 33 quoted lines
> 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.
Show 12 quoted lines
> @@ -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.
Show 7 quoted lines
>  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 */
Previous: Karthik NayakNext: Karthik Nayak
Message 20 of 64 in “refs/reftable: add fsck checks”
  1. 0/5 refs/reftable: add fsck checksKarthik Nayak, Aug 19, 2025
  2. 1/5 fsck: order 'fsck_msg_type' alphabeticallyKarthik Nayak, Aug 19, 2025
  3. 2/5 refs/reftable: add fsck check for checking the table nameKarthik Nayak, Aug 19, 2025
  4. shejialuoAug 26, 2025
  5. Karthik NayakSep 1, 2025
  6. shejialuoSep 3, 2025
  7. 3/5 refs/reftable: add fsck check for number of tablesKarthik Nayak, Aug 19, 2025
  8. shejialuoAug 26, 2025
  9. Karthik NayakSep 1, 2025
  10. shejialuoAug 26, 2025
  11. Karthik NayakSep 1, 2025
  12. 4/5 refs/reftable: add fsck check for trailing newlineKarthik Nayak, Aug 19, 2025
  13. 5/5 refs/reftable: add fsck check for incorrect update indexKarthik Nayak, Aug 19, 2025
  14. shejialuoAug 26, 2025
  15. Karthik NayakSep 1, 2025
  16. 0/8 refs/reftable: add consistency checksKarthik Nayak, Sep 18, 2025
  17. 1/8 refs: remove unused headersKarthik Nayak, Sep 18, 2025
  18. 2/8 refs: move consistency check msg to generic layerKarthik Nayak, Sep 18, 2025
  19. 3/8 reftable: check for trailing newline in 'tables.list'Karthik Nayak, Sep 18, 2025
  20. Junio C HamanoSep 18, 2025
  21. Karthik NayakSep 23, 2025
  22. Patrick SteinhardtSep 24, 2025
  23. Karthik NayakSep 24, 2025
  24. Kristoffer HaugsbakkSep 24, 2025
  25. Karthik NayakSep 24, 2025
  26. 5/8 Documentation/fsck-msgids: remove duplicate msg idKarthik Nayak, Sep 18, 2025
  27. 4/8 reftable: ensure tables in a stack use sequential update indicesKarthik Nayak, Sep 18, 2025
  28. Patrick SteinhardtSep 24, 2025
  29. Karthik NayakSep 24, 2025
  30. Junio C HamanoSep 24, 2025
  31. Karthik NayakSep 24, 2025
  32. Patrick SteinhardtSep 25, 2025
  33. Junio C HamanoSep 25, 2025
  34. 6/8 fsck: order 'fsck_msg_type' alphabeticallyKarthik Nayak, Sep 18, 2025
  35. 7/8 reftable: add code to facilitate consistency checksKarthik Nayak, Sep 18, 2025
  36. Patrick SteinhardtSep 24, 2025
  37. Karthik NayakSep 24, 2025
  38. Patrick SteinhardtSep 25, 2025
  39. 8/8 refs/reftable: add fsck check for checking the table nameKarthik Nayak, Sep 18, 2025
  40. Patrick SteinhardtSep 24, 2025
  41. Karthik NayakSep 24, 2025
  42. 0/7 refs/reftable: add consistency checksKarthik Nayak, Oct 6, 2025
  43. 1/7 refs: remove unused headersKarthik Nayak, Oct 6, 2025
  44. 2/7 refs: move consistency check msg to generic layerKarthik Nayak, Oct 6, 2025
  45. 3/7 reftable: check for trailing newline in 'tables.list'Karthik Nayak, Oct 6, 2025
  46. 4/7 Documentation/fsck-msgids: remove duplicate msg idKarthik Nayak, Oct 6, 2025
  47. 5/7 fsck: order 'fsck_msg_type' alphabeticallyKarthik Nayak, Oct 6, 2025
  48. 6/7 reftable: add code to facilitate consistency checksKarthik Nayak, Oct 6, 2025
  49. 7/7 refs/reftable: add fsck check for checking the table nameKarthik Nayak, Oct 6, 2025
  50. Jeff KingOct 7, 2025
  51. Karthik NayakOct 7, 2025
  52. Junio C HamanoOct 6, 2025
  53. Karthik NayakOct 7, 2025
  54. Junio C HamanoOct 7, 2025
  55. 0/7 refs/reftable: add consistency checksKarthik Nayak, Oct 7, 2025
  56. 1/7 refs: remove unused headersKarthik Nayak, Oct 7, 2025
  57. 2/7 refs: move consistency check msg to generic layerKarthik Nayak, Oct 7, 2025
  58. 3/7 reftable: check for trailing newline in 'tables.list'Karthik Nayak, Oct 7, 2025
  59. 4/7 Documentation/fsck-msgids: remove duplicate msg idKarthik Nayak, Oct 7, 2025
  60. 5/7 fsck: order 'fsck_msg_type' alphabeticallyKarthik Nayak, Oct 7, 2025
  61. 6/7 reftable: add code to facilitate consistency checksKarthik Nayak, Oct 7, 2025
  62. 7/7 refs/reftable: add fsck check for checking the table nameKarthik Nayak, Oct 7, 2025
  63. Patrick SteinhardtOct 7, 2025
  64. Junio C HamanoOct 7, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.