[OT] OT: Null checks.

Kagamin spam at here.lot
Mon May 5 08:19:20 UTC 2025


On Sunday, 4 May 2025 at 20:28:45 UTC, Timon Gehr wrote:
> I just remembered like half a year ago I have also seen a crash 
> once in
>
>
> ```
> private void _enforceNoOverlap(const char[] action,
>     uintptr_t ptr1, uintptr_t ptr2, const size_t bytes)
> {
>     const d = ptr1 > ptr2 ? ptr1 - ptr2 : ptr2 - ptr1;
>     if (d >= bytes)
>         return;
>     const overlappedBytes = bytes - d;
>
>     UnsignedStringBuf tmpBuff = void;
>     string msg = "Overlapping arrays in ";
>     msg ~= action;
>     msg ~= ": ";
>     msg ~= overlappedBytes.unsignedToTempString(tmpBuff);
>     msg ~= " byte(s) overlap of ";
>     msg ~= bytes.unsignedToTempString(tmpBuff);
>     assert(0, msg);
> }
> ```

That's a regression, also works with dmd: 
https://forum.dlang.org/post/krzyhjmbzkhqgolpemxz@forum.dlang.org

in 2.082 the code was
```
private void _enforceNoOverlap(const char[] action,
     uintptr_t ptr1, uintptr_t ptr2, in size_t bytes)
{
     const d = ptr1 > ptr2 ? ptr1 - ptr2 : ptr2 - ptr1;
     if(d >= bytes)
         return;
     const overlappedBytes = bytes - d;

     UnsignedStringBuf tmpBuff = void;
     string msg = "Overlapping arrays in ";
     msg ~= action;
     msg ~= ": ";
     msg ~= overlappedBytes.unsignedToTempString(tmpBuff, 10);
     msg ~= " byte(s) overlap of ";
     msg ~= bytes.unsignedToTempString(tmpBuff, 10);
     throw new Error(msg);
}
```


More information about the Digitalmars-d mailing list