[OT] OT: Null checks.

Timon Gehr timon.gehr at gmx.ch
Mon May 5 13:45:49 UTC 2025


On 5/5/25 10:19, Kagamin wrote:
> 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 at 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);
> }
> ```

https://github.com/dlang/dmd/commit/dda88738b2b391239c87cfdbd60b76d6025306e5







More information about the Digitalmars-d mailing list