Hi Kjetil,

On Dienstag, 7. Januar 2025 18:18:14 MEZ Kjetil Oftedal wrote:
> On Tue, 7 Jan 2025 at 18:07, Frank Mehnert
> <frank.mehn...@kernkonzept.com> wrote:
> >
> > On Dienstag, 7. Januar 2025 17:38:52 MEZ Kjetil Oftedal wrote:
> > > On Tue, 7 Jan 2025 at 17:09, Frank Mehnert
> > > <frank.mehn...@kernkonzept.com> 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, frank.mehn...@kernkonzept.com, +49-351-41 883 224

Kernkonzept GmbH.  Sitz: Dresden.  Amtsgericht Dresden, HRB 31129.
Geschäftsführer: Dr.-Ing. Michael Hohmuth


_______________________________________________
devel mailing list -- devel@uclibc-ng.org
To unsubscribe send an email to devel-le...@uclibc-ng.org

Reply via email to