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

[PATCH] strvec: use size_t to store nr and alloc

From
Jeff King <peff@peff.net>
Date
Sep 11, 2021, 15:01 UTC
Message-ID
<YTzEvLHWcfuD20x4@coredump.intra.peff.net>

We converted argv_array (which later became strvec) to use size_t in 819f0e76b1 (argv-array: use size_t for count and alloc, 2020-07-28) in order to avoid the possibility of integer overflow. But later, commit d70a9eb611 (strvec: rename struct fields, 2020-07-28) accidentally converted these back to ints!

Those two commits were part of the same patch series. I'm pretty sure what happened is that they were originally written in the opposite order and then cleaned up and re-ordered during an interactive rebase. And when resolving the inevitable conflict, I mistakenly took the "rename" patch completely, accidentally dropping the type change.

We can correct it now; better late than never.
Signed-off-by: Jeff King <peff@peff.net>
---
This was posted previously in the midst of another thread, but I don't
think was picked up. There was some positive reaction, but one "do we
really need this?" to which I responded in detail:
  https://lore.kernel.org/git/YTIBnT8Ue1HZXs82@coredump.intra.peff.net/

I don't really think any of that needs to go into the commit message, but if that's a hold-up, I can try to summarize it (though I think referring to the commit which _already_ did this and was accidentally reverted would be sufficient).

 strvec.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/strvec.h b/strvec.h
index fdcad75b45..6b3cbd6758 100644
--- a/strvec.h
+++ b/strvec.h
@@ -29,8 +29,8 @@ extern const char *empty_strvec[];
  */
 struct strvec {
 	const char **v;
-	int nr;
-	int alloc;
+	size_t nr;
+	size_t alloc;
 };
 
 #define STRVEC_INIT { empty_strvec, 0, 0 }
-- 
2.33.0.811.g40f7f3a89c
Next: Ævar Arnfjörð Bjarmason
Message 1 of 23 in “strvec: use size_t to store nr and alloc”
  1. strvec: use size_t to store nr and allocJeff King, Sep 11, 2021
  2. Ævar Arnfjörð BjarmasonSep 11, 2021
  3. Philip OakleySep 11, 2021
  4. 0/7 strvec: use size_t to store nr and allocÆvar Arnfjörð Bjarmason, Sep 12, 2021
  5. 1/7 remote-curl: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  6. Carlo ArenasSep 12, 2021
  7. Ævar Arnfjörð BjarmasonSep 13, 2021
  8. 2/7 pack-objects: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  9. 3/7 sequencer.[ch]: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  10. 4/7 upload-pack.c: pass "struct strvec *" instead of int/char ** pairÆvar Arnfjörð Bjarmason, Sep 12, 2021
  11. 5/7 rebase: don't have loop over "struct strvec" depend on signed "nr"Ævar Arnfjörð Bjarmason, Sep 12, 2021
  12. Eric SunshineSep 12, 2021
  13. 6/7 strvec: use size_t to store nr and allocÆvar Arnfjörð Bjarmason, Sep 12, 2021
  14. 7/7 strvec API users: change some "int" tracking "nr" to "size_t"Ævar Arnfjörð Bjarmason, Sep 12, 2021
  15. Eric SunshineSep 12, 2021
  16. Jeff KingSep 12, 2021
  17. Junio C HamanoSep 13, 2021
  18. Ævar Arnfjörð BjarmasonSep 13, 2021
  19. Jeff KingSep 13, 2021
  20. Philip OakleySep 13, 2021
  21. Jeff KingSep 12, 2021
  22. Philip OakleySep 13, 2021
  23. Jeff KingSep 12, 2021

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.