Re: [PATCH v2 1/4] revision: improve commit_rewrite_person()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add list back to cc

On 2022-07-08 23:23:07+0200, Christian Couder <christian.couder@xxxxxxxxx> wrote:
> On Fri, Jul 8, 2022 at 4:50 PM Đoàn Trần Công Danh <congdanhqx@xxxxxxxxx> wrote:
> >
> > On 2022-07-07 21:45:51+0530, Siddharth Asthana <siddharthasthana31@xxxxxxxxx> 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.

>
> > 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.


>>> +
>>> +             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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux