[OT] OT: Null checks.
Kagamin
spam at here.lot
Wed May 7 14:00:23 UTC 2025
On Tuesday, 6 May 2025 at 03:38:01 UTC, Timon Gehr wrote:
> Even better would be the type system just ensuring nullable
> pointers are never dereferenced, the OP's experience report
> notwithstanding. But I guess this part is a pipe dream for now.
If you suspect null dereference, it can be logged on windows:
```
void test()
{
static void Show(string message)
{
auto h=GetStdHandle(STD_ERROR_HANDLE);
uint n;
WriteFile(h,message.ptr,cast(int)message.length,&n,null);
}
extern(System)
static LONG VecHandler(in EXCEPTION_POINTERS* ex)
{
const er=ex.ExceptionRecord;
int code=er.ExceptionCode;
if(code==STATUS_ACCESS_VIOLATION)Show("access violation");
return EXCEPTION_CONTINUE_SEARCH;
}
AddVectoredExceptionHandler(0,&VecHandler) || assert(false);
byte* b=cast(byte*)1;
assert(b[1]==1);
}
```
More information about the Digitalmars-d
mailing list