Re: [PATCH v2 1/4] revision: improve commit_rewrite_person()
- From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
- Date
- Jul 9, 2022, 01:02 UTC
- Message-ID
- <YsjTif0TjYBzBXfh@danh.dev>
- In-Reply-To
- <CAP8UFD116xMnp27pxW8WNDf6PRJxnnwWtcy2TNHU_KyV2ZVA1g@mail.gmail.com>
Add list back to cc
On 2022-07-08 23:23:07+0200, Christian Couder <christian.couder@gmail.com> wrote:
Show 25 quoted lines
> On Fri, Jul 8, 2022 at 4:50 PM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> >
> > On 2022-07-07 21:45:51+0530, Siddharth Asthana <siddharthasthana31@gmail.com> wrote:
>
> > > By simplyfying the interface of the commit_rewrite_person(), we also
> >
> > s/simplyfying/simplifying/
>
> Thanks for noticing the typos!
>
> > > +static void commit_rewrite_person(struct strbuf *buf, const char **headers, struct string_list *mailmap)
> > > +{
> > > + size_t buf_offset = 0;
> > > +
> > > + if (!mailmap)
> > > + return;
> > > +
> > > + for (;;) {
> > > + const char *person, *line = buf->buf + buf_offset;
> > > + int i, linelen = strchrnul(line, '\n') - line + 1;
> >
> > Would you mind to change those lines to avoid mixed of declaration and
> > expression.
>
> I am not sure we have some clear guidelines on this.Yes, we don't have a clear guidelines on this, but this would sure matches into mixed declaration and expression. And some variables are initialized and some aren't in the same line. I was confused in my first glance.
Show 16 quoted lines
> > > Also, I think i and linelen should be ssize_t instead. > > Could you explain why? > > I think 'i' is changed only in: > > for (i = 0; headers[i]; i++) > > and therefore cannot be négative. > > While linelen is set only in: > > linelen = strchrnul(line, '\n') - line + 1; > > and therefore cannot be négative either.
Yes, both of them can't be negative. As I explained in the part you removed. However, I choose ssize_t in my reply because it's a ptrdiff_t.
So, size_t is an obviously a better choice. Either size_t and ssize_t could be used in this case, but not int.
Show 8 quoted lines
>>> + >>> + if (!linelen || linelen == 1) >>> + /* End of header */ >>> + return; >> >>And I think linelen will never be 0 or negative, >>even if linelen could be 0, I think we want "linelen != 0" >>for integer comparision.
-- Danh