]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/no-writable-strings'
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Jun 2024 22:55:57 +0000 (15:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jun 2024 22:55:58 +0000 (15:55 -0700)
Building with "-Werror -Wwrite-strings" is now supported.

* ps/no-writable-strings: (27 commits)
  config.mak.dev: enable `-Wwrite-strings` warning
  builtin/merge: always store allocated strings in `pull_twohead`
  builtin/rebase: always store allocated string in `options.strategy`
  builtin/rebase: do not assign default backend to non-constant field
  imap-send: fix leaking memory in `imap_server_conf`
  imap-send: drop global `imap_server_conf` variable
  mailmap: always store allocated strings in mailmap blob
  revision: always store allocated strings in output encoding
  remote-curl: avoid assigning string constant to non-const variable
  send-pack: always allocate receive status
  parse-options: cast long name for OPTION_ALIAS
  http: do not assign string constant to non-const field
  compat/win32: fix const-correctness with string constants
  pretty: add casts for decoration option pointers
  object-file: make `buf` parameter of `index_mem()` a constant
  object-file: mark cached object buffers as const
  ident: add casts for fallback name and GECOS
  entry: refactor how we remove items for delayed checkouts
  line-log: always allocate the output prefix
  line-log: stop assigning string constant to file parent buffer
  ...

19 files changed:
1  2 
builtin/blame.c
builtin/clone.c
builtin/fetch.c
builtin/remote.c
fsck.c
fsck.h
imap-send.c
object-file.c
refs.c
refs.h
refs/reftable-backend.c
reftable/merged_test.c
reftable/readwrite_test.c
reftable/stack.c
reftable/stack_test.c
remote-curl.c
run-command.c
t/unit-tests/t-reftable-basics.c
wt-status.c

diff --cc builtin/blame.c
Simple merge
diff --cc builtin/clone.c
Simple merge
diff --cc builtin/fetch.c
Simple merge
Simple merge
diff --cc fsck.c
Simple merge
diff --cc fsck.h
Simple merge
diff --cc imap-send.c
index 185104d0198ae1c6b6902ae1cc5f99ab800e09d1,da3e7ec17e526336172fee879e13ac798111441d..e602edc4be1deed95f144f883559178a18558db9
@@@ -1543,9 -1555,9 +1555,10 @@@ int cmd_main(int argc, const char **arg
        }
  
        if (all_msgs.len == 0) {
 +              strbuf_release(&all_msgs);
                fprintf(stderr, "nothing to send\n");
-               return 1;
+               ret = 1;
+               goto out;
        }
  
        total = count_messages(&all_msgs);
diff --cc object-file.c
Simple merge
diff --cc refs.c
Simple merge
diff --cc refs.h
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 6b8136e8e20dda907b4da2e380eb8ec9509772c7,4abf92636d93c9e39a0207b35c331dc1375640b2..e3c11e6a6eebb099629aafa23037de0b10caacba
@@@ -383,19 -409,19 +383,19 @@@ static void test_reftable_stack_update_
        struct reftable_stack *st = NULL;
        int err;
        struct reftable_ref_record ref1 = {
-               .refname = "name1",
+               .refname = (char *) "name1",
                .update_index = 1,
                .value_type = REFTABLE_REF_SYMREF,
-               .value.symref = "master",
+               .value.symref = (char *) "master",
        };
        struct reftable_ref_record ref2 = {
-               .refname = "name2",
+               .refname = (char *) "name2",
                .update_index = 1,
                .value_type = REFTABLE_REF_SYMREF,
-               .value.symref = "master",
+               .value.symref = (char *) "master",
        };
  
 -      err = reftable_new_stack(&st, dir, cfg);
 +      err = reftable_new_stack(&st, dir, &opts);
        EXPECT_ERR(err);
  
        err = reftable_stack_add(st, &write_test_ref, &ref1);
@@@ -552,10 -579,10 +552,10 @@@ static void test_reftable_stack_log_nor
                .update_index = 1,
        };
  
 -      err = reftable_new_stack(&st, dir, cfg);
 +      err = reftable_new_stack(&st, dir, &opts);
        EXPECT_ERR(err);
  
-       input.value.update.message = "one\ntwo";
+       input.value.update.message = (char *) "one\ntwo";
        err = reftable_stack_add(st, &write_test_log, &arg);
        EXPECT(err == REFTABLE_API_ERROR);
  
@@@ -667,14 -697,14 +667,14 @@@ static void test_reftable_stack_hash_id
        int err;
  
        struct reftable_ref_record ref = {
-               .refname = "master",
+               .refname = (char *) "master",
                .value_type = REFTABLE_REF_SYMREF,
-               .value.symref = "target",
+               .value.symref = (char *) "target",
                .update_index = 1,
        };
 -      struct reftable_write_options cfg32 = { .hash_id = GIT_SHA256_FORMAT_ID };
 +      struct reftable_write_options opts32 = { .hash_id = GIT_SHA256_FORMAT_ID };
        struct reftable_stack *st32 = NULL;
 -      struct reftable_write_options cfg_default = { 0 };
 +      struct reftable_write_options opts_default = { 0 };
        struct reftable_stack *st_default = NULL;
        struct reftable_ref_record dest = { NULL };
  
diff --cc remote-curl.c
Simple merge
diff --cc run-command.c
Simple merge
index 529049af128ab5d6bfc359380e3938ef0a12bcfc,0000000000000000000000000000000000000000..4e80bdf16df0deb46d48ce01e548fb75ef466a79
mode 100644,000000..100644
--- /dev/null
@@@ -1,160 -1,0 +1,160 @@@
-       char *a[] = { "a", "b", NULL };
 +/*
 +Copyright 2020 Google LLC
 +
 +Use of this source code is governed by a BSD-style
 +license that can be found in the LICENSE file or at
 +https://developers.google.com/open-source/licenses/bsd
 +*/
 +
 +#include "test-lib.h"
 +#include "reftable/basics.h"
 +
 +struct integer_needle_lesseq_args {
 +      int needle;
 +      int *haystack;
 +};
 +
 +static int integer_needle_lesseq(size_t i, void *_args)
 +{
 +      struct integer_needle_lesseq_args *args = _args;
 +      return args->needle <= args->haystack[i];
 +}
 +
 +static void test_binsearch(void)
 +{
 +      int haystack[] = { 2, 4, 6, 8, 10 };
 +      struct {
 +              int needle;
 +              size_t expected_idx;
 +      } testcases[] = {
 +              {-9000, 0},
 +              {-1, 0},
 +              {0, 0},
 +              {2, 0},
 +              {3, 1},
 +              {4, 1},
 +              {7, 3},
 +              {9, 4},
 +              {10, 4},
 +              {11, 5},
 +              {9000, 5},
 +      };
 +
 +      for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
 +              struct integer_needle_lesseq_args args = {
 +                      .haystack = haystack,
 +                      .needle = testcases[i].needle,
 +              };
 +              size_t idx;
 +
 +              idx = binsearch(ARRAY_SIZE(haystack), &integer_needle_lesseq, &args);
 +              check_int(idx, ==, testcases[i].expected_idx);
 +      }
 +}
 +
 +static void test_names_length(void)
 +{
-       char *a[] = { "a", "b", "c", NULL };
-       char *b[] = { "a", "b", "d", NULL };
-       char *c[] = { "a", "b", NULL };
++      const char *a[] = { "a", "b", NULL };
 +      check_int(names_length(a), ==, 2);
 +}
 +
 +static void test_names_equal(void)
 +{
++      const char *a[] = { "a", "b", "c", NULL };
++      const char *b[] = { "a", "b", "d", NULL };
++      const char *c[] = { "a", "b", NULL };
 +
 +      check(names_equal(a, a));
 +      check(!names_equal(a, b));
 +      check(!names_equal(a, c));
 +}
 +
 +static void test_parse_names_normal(void)
 +{
 +      char in1[] = "line\n";
 +      char in2[] = "a\nb\nc";
 +      char **out = NULL;
 +      parse_names(in1, strlen(in1), &out);
 +      check_str(out[0], "line");
 +      check(!out[1]);
 +      free_names(out);
 +
 +      parse_names(in2, strlen(in2), &out);
 +      check_str(out[0], "a");
 +      check_str(out[1], "b");
 +      check_str(out[2], "c");
 +      check(!out[3]);
 +      free_names(out);
 +}
 +
 +static void test_parse_names_drop_empty(void)
 +{
 +      char in[] = "a\n\nb\n";
 +      char **out = NULL;
 +      parse_names(in, strlen(in), &out);
 +      check_str(out[0], "a");
 +      /* simply '\n' should be dropped as empty string */
 +      check_str(out[1], "b");
 +      check(!out[2]);
 +      free_names(out);
 +}
 +
 +static void test_common_prefix(void)
 +{
 +      struct strbuf a = STRBUF_INIT;
 +      struct strbuf b = STRBUF_INIT;
 +      struct {
 +              const char *a, *b;
 +              int want;
 +      } cases[] = {
 +              {"abcdef", "abc", 3},
 +              { "abc", "ab", 2 },
 +              { "", "abc", 0 },
 +              { "abc", "abd", 2 },
 +              { "abc", "pqr", 0 },
 +      };
 +
 +      for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
 +              strbuf_addstr(&a, cases[i].a);
 +              strbuf_addstr(&b, cases[i].b);
 +              check_int(common_prefix_size(&a, &b), ==, cases[i].want);
 +              strbuf_reset(&a);
 +              strbuf_reset(&b);
 +      }
 +      strbuf_release(&a);
 +      strbuf_release(&b);
 +}
 +
 +static void test_u24_roundtrip(void)
 +{
 +      uint32_t in = 0x112233;
 +      uint8_t dest[3];
 +      uint32_t out;
 +      put_be24(dest, in);
 +      out = get_be24(dest);
 +      check_int(in, ==, out);
 +}
 +
 +static void test_u16_roundtrip(void)
 +{
 +      uint32_t in = 0xfef1;
 +      uint8_t dest[3];
 +      uint32_t out;
 +      put_be16(dest, in);
 +      out = get_be16(dest);
 +      check_int(in, ==, out);
 +}
 +
 +int cmd_main(int argc, const char *argv[])
 +{
 +      TEST(test_common_prefix(), "common_prefix_size works");
 +      TEST(test_parse_names_normal(), "parse_names works for basic input");
 +      TEST(test_parse_names_drop_empty(), "parse_names drops empty string");
 +      TEST(test_binsearch(), "binary search with binsearch works");
 +      TEST(test_names_length(), "names_length retuns size of a NULL-terminated string array");
 +      TEST(test_names_equal(), "names_equal compares NULL-terminated string arrays");
 +      TEST(test_u24_roundtrip(), "put_be24 and get_be24 work");
 +      TEST(test_u16_roundtrip(), "put_be16 and get_be16 work");
 +
 +      return test_done();
 +}
diff --cc wt-status.c
Simple merge