On Wed, 8 Jan 2025 at 11:42, Frank Mehnert
<[email protected]> wrote:
>
> Hi Kjetil,
>
> On Dienstag, 7. Januar 2025 18:18:14 MEZ Kjetil Oftedal wrote:
> > On Tue, 7 Jan 2025 at 18:07, Frank Mehnert
> > <[email protected]> wrote:
> > >
> > > On Dienstag, 7. Januar 2025 17:38:52 MEZ Kjetil Oftedal wrote:
> > > > On Tue, 7 Jan 2025 at 17:09, Frank Mehnert
> > > > <[email protected]> wrote:
> > > >
> > > > [...]
> > > >
> > > > Is this true for all cases for strings?
> > > >
> > > > > In the original case (end_ptr < str), the compiler knows for sure that
> > > > > both pointers belong to different objects!
> > > >
> > > > ---
> > > > const char* str = "Hello World!"
> > > > const char* sub_str = strstr(str, "Wor");
> > > >
> > > > strnlen(sub_str, X);
> > > > ---
> > > >
> > > > For some values of X end_ptr is still pointing to a valid array entry
> > > > for the original "Hello World" string,
> > > > even if it is not within the "World!" substring. Is it then not
> > > > pointing to a valid array of objects?
> > > > (E.g if X is the unsigned representation of -1,-2,...-6)
> > >
> > > OK, I think you have a point.
> > >
> > > Basically this derives into the question if adding a huge offset to a 
> > > pointer
> > > is the same as subtracting a small offset from a pointer. So far I 
> > > couldn't
> > > find any C++ rule related to this problem.
> >
> > Hi,
> >
> > I think it is purely academic as this point though :)
> >
> > The change is probably fine. Just a bit annoyed that clang forces
> > changes to the code
> > in a lot of projects, instead of clang accepting defacto standard patterns.
>
> The LLVM ticket [1] was updated and Andrew Pinski noted that the the Linux
> kernel, -fwrapv-pointer was added to keep the "defacto standard patterns".
> So compiling with -fno-strict-overflow (which included -fwrapv-pointer) would
> most likely make my fix superfluous.
>
> So it's basically about pointer arithmetics warp around.
>
> But I hope there is agreement now that my change makes the code "more 
> correct".
>
> Kind regards
>
> Frank
>
> [1] https://github.com/llvm/llvm-project/issues/121909
> --
> Dr.-Ing. Frank Mehnert, [email protected], +49-351-41 883 224
>
> Kernkonzept GmbH.  Sitz: Dresden.  Amtsgericht Dresden, HRB 31129.
> Geschäftsführer: Dr.-Ing. Michael Hohmuth
>

Sure. I enjoyed the discussion. There is no objection from me on the change.

Best regards,
Kjetil Oftedal
_______________________________________________
devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to