class CWindow {
HWND handle;
public:
HWND GetSafeHandle() const
{
return this == 0 ? 0 : handle;
}
};
struct CWindow {
CWindow() : handle() {}
int handle;
int GetSafeHandle() const
{
return (this == 0) ? 1 : handle;
}
};
int main()
{
CWindow* wnd = 0;
return wnd->GetSafeHandle();
}
main:
movl 0, %eax
ud2
main:
movl $1, %eax
ret
int GetSafeHandle() const __attribute__ ((noinline))
CWindow::GetSafeHandle() const:
testq %rdi, %rdi
je .L1
movl (%rdi), %eax
ret
.L1:
movl $1, %eax
ret
main:
xorl %edi, %edi
jmp CWindow::GetSafeHandle() const
CWindow::GetSafeHandle() const:
movl (%rdi), %eax
ret
main:
xorl %edi, %edi
jmp CWindow::GetSafeHandle() const
int GetSafeHandle() const __attribute__ ((noinline))
{
if (this == 0) // -Wnonnull-compare
return 1;
if((this == 0))
return 1; //
return this == 0 ? 1 : handle; // -Wnonnull-compare
return (this == 0) ? 1 : handle; //
}
if (this == 0);
(this == 0) ? 1 : handle;
if(this != 0);
(this != 0) ? handle : 1;
if(this);
this ? handle : 1;
if(!this);
!this ? 1 : handle;
Source: https://habr.com/ru/post/308346/
All Articles