Re: [hackers] [PATCH][sbase] Add patch(1)

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Mon, 25 Sep 2017 08:34:56 +0200

On Sun, Sep 24, 2017 at 8:57 PM, Mattias Andrée <maandree_AT_kth.se> wrote:
> On Sun, 24 Sep 2017 19:24:10 +0200
> Silvan Jegen <s.jegen_AT_gmail.com> wrote:
>
>> Heyho
>>
>> On Sun, Sep 24, 2017 at 06:28:57PM +0200, Mattias Andrée wrote:
>> > On Sun, 24 Sep 2017 14:08:41 +0200
>> > Silvan Jegen <s.jegen_AT_gmail.com> wrote:
>> >
>> > > > +
>> > > > + if (!new->len)
>> > > > + for (i = 0; i < old->len; i++)
>> > > > + if (old->lines[i].data[-2] != '-')
>> > >
>> > > I think according to the standard, refering to data[-2] invokes undefined
>> > > behaviour, since at this time, data points to the beginning of the array.
>> >
>> > I'm not sure whether it is defined or undefined; I would think that it
>> > defined, but that adding integers larger than INTPTR_MAX is undefined.
>> > I will change to `*(data - 2)` as this is clearly defined.
>>
>> I was referring to
>> https://stackoverflow.com/questions/3473675/are-negative-array-indexes-allowed-in-c/3473686#3473686
>> . `*(data -2) is equivalent to 'data[-2]' but since 'data' doesn't point
>> to the second element of the array, I don't think this is valid.
>
> Hi!
>
> I think there has been some misunderstanding here,
> and that we are in agreement that `a[-b]` in it self
> is not invalid, but that question is whether the
> deferenced address is valid. I understand why this
> looks incorrect, `old->lines->data[0]` does not
> actually point to the first character on a line
> in a line but rather to the first character in the
> line that is part of the content of the file that
> hunk patches. For example if the patchfile contains
> the line "- abc", `old->lines->data[0]` is `a`, not
> `-`, because "- " part of the annotations in the
> hunk.

Ah, I missed that. In that case this negative index is ok.


> This should probably be clarified, but you can see
> that this happening just above this code.

Pointing this out in a comment seems like a good idea to me.


> I will look that your other comments later.

Sure!


Cheers,

Silvan
Received on Mon Sep 25 2017 - 08:34:56 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 25 2017 - 08:36:21 CEST