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

Re: [PATCH 3/3] parse: replace atoi() with strtoul_ui() and strtol_i()

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 17, 2024, 12:02 UTC
Message-ID
<ZxD84l-tcU0TrX1K@pks.im>
In-Reply-To
<CAPSxiM-Yw2H65+EHoDckU2N2hr+UrXRu5Y2JjXc+TEwEUKJT0Q@mail.gmail.com>
On Thu, Oct 17, 2024 at 11:56:33AM +0000, Usman Akinyemi wrote:
Show 56 quoted lines
> On Mon, Oct 14, 2024 at 6:36 PM <phillip.wood123@gmail.com> wrote:
> >
> > On 14/10/2024 17:26, Usman Akinyemi wrote:
> > > On Mon, Oct 14, 2024 at 4:13 PM Usman Akinyemi
> > >> On Mon, Oct 14, 2024 at 2:55 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
> > >> I got this from a leftoverbit which the main issue was reported as
> > >> bug. https://public-inbox.org/git/CAC4O8c-nuOTS=a0sVp1603KaM2bZjs+yNZzdAaa5CGTNGFE7hQ@mail.gmail.com/
> > >> For the test, I should have the test as another patch right ?
> >
> > In general you should add tests in the same commit as the code changes
> > that they test. In this instance I think you want to split this patch
> > into three, one patch for git-daemon, one for imap-send and one for the
> > merge marker config changes. Each patch should have a commit message
> > explaining the changes and whether they change the behavior of the code
> > (for example rejecting non-numbers) and add some tests. Note that I
> > don't think it is possible to test the imap-send changes but the other
> > two should be easy enough. The tests should be added to one of the
> > existing test files that are testing the code being changed.
> Hello,
> I am currently facing some issues while trying to write the test for
> daemon.c, I need some help on it.
> The start_git_daemon function inside lib-git-daemon.sh is made to
> allow --init-timeout, --max-connections and
> timeout as well as other arguments. The start_git_daemon function in
> lib-git-daemon.sh is used at t5570-git-daemon.sh.
> Basically this is my changes
>                 if (skip_prefix(arg, "--timeout=", &v)) {
> -                       timeout = atoi(v);
> +                       if (strtoul_ui(v, 10, &timeout))
> +                               die("invalid timeout '%s', expecting a
> non-negative integer", v);
>                         continue;
>                 }
>                 if (skip_prefix(arg, "--init-timeout=", &v)) {
> -                       init_timeout = atoi(v);
> +                       if (strtoul_ui(v, 10, &init_timeout))
> +                               die("invalid init-timeout '%s',
> expecting a non-negative integer", v);
>                         continue;
>                 }
>                 if (skip_prefix(arg, "--max-connections=", &v)) {
> -                       max_connections = atoi(v);
> +                       if (strtol_i(v, 10, &max_connections))
> +                               die("invalid '--max-connections' '%s',
> expecting an integer", v);
>                         if (max_connections < 0)
> -                               max_connections = 0;            /* unlimited */
> +                               max_connections = 0;  /* unlimited */
>                         continue;
>                 }
> What happened is that the start_git_daemon will already fail and will
> prevent the
> t5570-git-daemon.sh from starting if there is any wrong starting
> condition such as the new
> changes I added. I am finding it hard to come up with an approach to
> test the new change.

I'd just not use `start_git_daemon ()` in the first place. Instead, I'd invoke git-daemon(1) directly with invalid options and then observe that it fails to start up with the expected error message.

Patrick
Previous: Usman AkinyemiNext: Usman Akinyemi
Message 24 of 94 in “R atoi”
  1. 0/3 R atoiUsman Akinyemi via GitGitGadget, Oct 12, 2024
  2. 1/3 t3404: avoid losing exit status with focus on `git show` and `git cat-file`Usman Akinyemi via GitGitGadget, Oct 12, 2024
  3. Taylor BlauOct 14, 2024
  4. 2/3 t3404: replace test with test_line_count()Usman Akinyemi via GitGitGadget, Oct 12, 2024
  5. Taylor BlauOct 14, 2024
  6. 3/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 12, 2024
  7. Usman AkinyemiOct 13, 2024
  8. Phillip WoodOct 14, 2024
  9. Usman AkinyemiOct 14, 2024
  10. Patrick SteinhardtOct 14, 2024
  11. Phillip WoodOct 14, 2024
  12. Patrick SteinhardtOct 14, 2024
  13. Phillip WoodOct 14, 2024
  14. Usman AkinyemiOct 14, 2024
  15. Usman AkinyemiOct 14, 2024
  16. phillip.wood123@gmail.comOct 14, 2024
  17. Usman AkinyemiOct 15, 2024
  18. Taylor BlauOct 15, 2024
  19. Usman AkinyemiOct 16, 2024
  20. phillip.wood123@gmail.comOct 15, 2024
  21. Phillip WoodOct 16, 2024
  22. Usman AkinyemiOct 16, 2024
  23. Usman AkinyemiOct 17, 2024
  24. Patrick SteinhardtOct 17, 2024
  25. Usman AkinyemiOct 17, 2024
  26. Usman AkinyemiOct 14, 2024
  27. Phillip WoodOct 14, 2024
  28. Kristoffer HaugsbakkOct 14, 2024
  29. Phillip WoodOct 14, 2024
  30. Usman AkinyemiOct 14, 2024
  31. phillip.wood123@gmail.comOct 14, 2024
  32. Usman AkinyemiOct 17, 2024
  33. 0/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 18, 2024
  34. 1/3 daemon: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 18, 2024
  35. Patrick SteinhardtOct 21, 2024
  36. Usman AkinyemiOct 21, 2024
  37. Taylor BlauOct 21, 2024
  38. Usman AkinyemiOct 21, 2024
  39. 2/3 merge: replace atoi() with strtol_i() for marker size validationUsman Akinyemi via GitGitGadget, Oct 18, 2024
  40. Patrick SteinhardtOct 21, 2024
  41. Usman AkinyemiOct 21, 2024
  42. Taylor BlauOct 21, 2024
  43. Usman AkinyemiOct 21, 2024
  44. Usman AkinyemiOct 21, 2024
  45. Taylor BlauOct 21, 2024
  46. Phillip WoodOct 30, 2024
  47. Usman AkinyemiOct 30, 2024
  48. Phillip WoodOct 31, 2024
  49. Usman AkinyemiOct 31, 2024
  50. Usman AkinyemiNov 6, 2024
  51. phillip.wood123@gmail.comNov 6, 2024
  52. 3/3 imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsingUsman Akinyemi via GitGitGadget, Oct 18, 2024
  53. Patrick SteinhardtOct 21, 2024
  54. Usman AkinyemiOct 21, 2024
  55. Patrick SteinhardtOct 21, 2024
  56. Usman AkinyemiOct 21, 2024
  57. Taylor BlauOct 21, 2024
  58. Usman AkinyemiOct 21, 2024
  59. Usman AkinyemiOct 22, 2024
  60. Taylor BlauOct 18, 2024
  61. Usman AkinyemiOct 18, 2024
  62. Taylor BlauOct 18, 2024
  63. Usman AkinyemiOct 18, 2024
  64. 0/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 22, 2024
  65. 1/3 daemon: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 22, 2024
  66. Taylor BlauOct 22, 2024
  67. Usman AkinyemiOct 22, 2024
  68. 2/3 merge: replace atoi() with strtol_i() for marker size validationUsman Akinyemi via GitGitGadget, Oct 22, 2024
  69. 3/3 imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsingUsman Akinyemi via GitGitGadget, Oct 22, 2024
  70. 0/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 22, 2024
  71. 1/3 daemon: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 22, 2024
  72. 2/3 merge: replace atoi() with strtol_i() for marker size validationUsman Akinyemi via GitGitGadget, Oct 22, 2024
  73. 3/3 imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsingUsman Akinyemi via GitGitGadget, Oct 22, 2024
  74. Patrick SteinhardtOct 23, 2024
  75. Usman AkinyemiOct 23, 2024
  76. 0/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 23, 2024
  77. 1/3 daemon: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 23, 2024
  78. Taylor BlauOct 23, 2024
  79. Usman AkinyemiOct 24, 2024
  80. 2/3 merge: replace atoi() with strtol_i() for marker size validationUsman Akinyemi via GitGitGadget, Oct 23, 2024
  81. Taylor BlauOct 23, 2024
  82. Usman AkinyemiOct 24, 2024
  83. 3/3 imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsingUsman Akinyemi via GitGitGadget, Oct 23, 2024
  84. Patrick SteinhardtOct 23, 2024
  85. Taylor BlauOct 23, 2024
  86. Usman AkinyemiOct 24, 2024
  87. 0/3 parse: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 24, 2024
  88. 1/3 daemon: replace atoi() with strtoul_ui() and strtol_i()Usman Akinyemi via GitGitGadget, Oct 24, 2024
  89. 2/3 merge: replace atoi() with strtol_i() for marker size validationUsman Akinyemi via GitGitGadget, Oct 24, 2024
  90. 3/3 imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsingUsman Akinyemi via GitGitGadget, Oct 24, 2024
  91. Taylor BlauOct 24, 2024
  92. Patrick SteinhardtOct 25, 2024
  93. Usman AkinyemiOct 25, 2024
  94. Taylor BlauOct 25, 2024

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.