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

From: Mattias Andrée <maandree_AT_kth.se>
Date: Sun, 24 Sep 2017 20:57:15 +0200

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.

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

I will look that your other comments later.

Received on Sun Sep 24 2017 - 20:57:15 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 24 2017 - 21:00:23 CEST