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

[PATCH v2 0/2] string-list.h: make "nr" and "alloc" a "size_t"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 7, 2022, 15:27 UTC
Message-ID
<cover-v2-0.2-00000000000-20220307T152316Z-avarab@gmail.com>
In-Reply-To
<cover-0.2-00000000000-20220307T113707Z-avarab@gmail.com>

Change the "struct string_list" to have a "size_t" for "nr" and "alloc", ensuring we won't overflow on platforms where size_t is 64 bit, but "unsigned int" is 32 bit.

This replaces the v1 1/2 to get rid of the casts we use for Q_(), and the 2/2's addition of casts is then consistent with those.

Ævar Arnfjörð Bjarmason (2):
  gettext API users: don't explicitly cast ngettext()'s "n"
  string-list API: change "nr" and "alloc" to "size_t"
 builtin/index-pack.c        |  2 +-
 builtin/merge-recursive.c   |  2 +-
 builtin/receive-pack.c      |  9 +++++----
 builtin/shortlog.c          | 10 +++++-----
 bundle.c                    |  8 ++++----
 commit-graph.c              |  6 +++---
 mailmap.c                   |  7 ++++---
 merge-ort.c                 |  4 ++--
 strbuf.c                    |  4 ++--
 string-list.h               |  3 ++-
 t/helper/test-run-command.c |  7 ++++---
 wt-status.c                 | 12 ++++++------
 12 files changed, 39 insertions(+), 35 deletions(-)
Range-diff against v1:
1:  83659fbc459 < -:  ----------- gettext API users: correct use of casts for Q_()
-:  ----------- > 1:  83fd21741ad gettext API users: don't explicitly cast ngettext()'s "n"
2:  398682c07aa ! 2:  6db8ab7a121 string-list API: change "nr" and "alloc" to "size_t"
    @@ Commit message
         two lines, which is the case for most such struct member
         declarations (e.g. in "strbuf.h" and "strvec.h").
     
    +    Changing e.g. "int i" to "size_t i" in run_and_feed_hook() isn't
    +    strictly necessary, and there are a lot more cases where we'll use a
    +    local "int", "unsigned int" etc. variable derived from the "nr" in the
    +    "struct string_list". But in that case as well as
    +    add_wrapped_shortlog_msg() in builtin/shortlog.c we need to adjust the
    +    printf format referring to "nr" anyway, so let's also change the other
    +    variables referring to it.
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## builtin/receive-pack.c ##
    @@ bundle.c: int verify_bundle(struct repository *r,
      		r = &header->references;
      		printf_ln(Q_("The bundle contains this ref:",
     -			     "The bundle contains these %d refs:",
    --			     r->nr),
    --			  r->nr);
     +			     "The bundle contains these %"PRIuMAX" refs:",
    -+			     (unsigned long)r->nr),
    + 			     r->nr),
    +-			  r->nr);
     +			  (uintmax_t)r->nr);
      		list_refs(r, 0, NULL);
      		r = &header->prerequisites;
    @@ bundle.c: int verify_bundle(struct repository *r,
      		} else {
      			printf_ln(Q_("The bundle requires this ref:",
     -				     "The bundle requires these %d refs:",
    --				     r->nr),
    --				  r->nr);
     +				     "The bundle requires these %"PRIuMAX" refs:",
    -+				     (unsigned long)r->nr),
    + 				     r->nr),
    +-				  r->nr);
     +				  (uintmax_t)r->nr);
      			list_refs(r, 0, NULL);
      		}
    @@ commit-graph.c: static int fill_oids_from_packs(struct write_commit_graph_contex
      		strbuf_addf(&progress_title,
     -			    Q_("Finding commits for commit graph in %d pack",
     -			       "Finding commits for commit graph in %d packs",
    --			       pack_indexes->nr),
    --			    pack_indexes->nr);
     +			    Q_("Finding commits for commit graph in %"PRIuMAX" pack",
     +			       "Finding commits for commit graph in %"PRIuMAX" packs",
    -+			       (unsigned long)pack_indexes->nr),
    + 			       pack_indexes->nr),
    +-			    pack_indexes->nr);
     +			    (uintmax_t)pack_indexes->nr);
      		ctx->progress = start_delayed_progress(progress_title.buf, 0);
      		ctx->progress_done = 0;
    @@ wt-status.c: static void show_rebase_information(struct wt_status *s,
      			status_printf_ln(s, color,
     -				Q_("Last command done (%d command done):",
     -					"Last commands done (%d commands done):",
    --					have_done.nr),
    --				have_done.nr);
     +				Q_("Last command done (%"PRIuMAX" command done):",
     +					"Last commands done (%"PRIuMAX" commands done):",
    -+					(unsigned long)have_done.nr),
    + 					have_done.nr),
    +-				have_done.nr);
     +				(uintmax_t)have_done.nr);
      			for (i = (have_done.nr > nr_lines_to_show)
      				? have_done.nr - nr_lines_to_show : 0;
    @@ wt-status.c: static void show_rebase_information(struct wt_status *s,
      			status_printf_ln(s, color,
     -				Q_("Next command to do (%d remaining command):",
     -					"Next commands to do (%d remaining commands):",
    --					yet_to_do.nr),
    --				yet_to_do.nr);
     +				Q_("Next command to do (%"PRIuMAX" remaining command):",
     +					"Next commands to do (%"PRIuMAX" remaining commands):",
    -+					(unsigned long)yet_to_do.nr),
    + 					yet_to_do.nr),
    +-				yet_to_do.nr);
     +				(uintmax_t)yet_to_do.nr);
      			for (i = 0; i < nr_lines_to_show && i < yet_to_do.nr; i++)
      				status_printf_ln(s, color, "   %s", yet_to_do.items[i].string);
-- 
2.35.1.1242.gfeba0eae32b
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 9 of 15 in “string-list.h: make "nr" and "alloc" a "size_t"”
  1. 0/2 string-list.h: make "nr" and "alloc" a "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  2. 1/2 gettext API users: correct use of casts for Q_()Ævar Arnfjörð Bjarmason, Mar 7, 2022
  3. Derrick StoleeMar 7, 2022
  4. Ævar Arnfjörð BjarmasonMar 7, 2022
  5. Derrick StoleeMar 7, 2022
  6. 2/2 string-list API: change "nr" and "alloc" to "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  7. Derrick StoleeMar 7, 2022
  8. Ævar Arnfjörð BjarmasonMar 7, 2022
  9. 0/2 string-list.h: make "nr" and "alloc" a "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  10. 1/2 gettext API users: don't explicitly cast ngettext()'s "n"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  11. 2/2 string-list API: change "nr" and "alloc" to "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  12. Philip OakleyMar 7, 2022
  13. Junio C HamanoMar 7, 2022
  14. Philip OakleyMar 7, 2022
  15. Derrick StoleeMar 7, 2022

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.