[OT] OT: Null checks.
Timon Gehr
timon.gehr at gmx.ch
Tue May 6 03:11:00 UTC 2025
On 5/6/25 03:43, Walter Bright wrote:
> On 5/4/2025 1:28 PM, Timon Gehr wrote:
>> ```
>> 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);
>> }
>> ```
>
> I would not write logging code like that that relied on the gc being in
> a working state.
> ...
Well, this is copied from druntime.
>> Unfortunately I had accidentally detached my debugger instead of
>> getting the backtrace at the time. It is possible that this is what is
>> happening on the user's machine, but I don't know. And I also have no
>> idea where this overlap might occur.
>>
>> This just gives an invalid instruction even in dubs "release-debug"
>> builds by default unless using a custom druntime build. I just don't
>> think this should ever happen to anyone, even if there is some
>> workaround, by default people will run into this at least once and
>> perhaps they will not be as lucky as me and see it with a debugger
>> attached.
>>
>
> The -release switch causes `assert(0, "message")` to be replaced with
> "ud2" which generates a breakpoint for the debugger. It triggers an
> invalid opcode exception.
>
> You could write a signal handler to intercept that. See my other post
> for how to write one.
Well, I can. I should not have to do that though to get basic
functionality that is a given in some other languages. I replied to the
other post.
More information about the Digitalmars-d
mailing list