Re: [edk2] Common, pedantic, bug in embedded C. * (char *)0x00000000 = 1

Subject: Re: [edk2] Common, pedantic, bug in embedded C. * (char *)0x00000000 = 1

From: Paolo Bonzini <>


Date: 2013-03-08 21:14:24

Il 08/03/2013 01:14, Andrew Fish ha scritto:
> We just ran into an issue that I thought was worth sharing with the
> group. We just updated our compiler and a memory test got optimized
> away. At first we thought it was a compiler bug. But then we were
> informed that in the C language the dereference of a NULL pointer is
> undefined behavior. So technically it is legal for the compiler to
> optimize it way.
> So to be pedantic in C if you ever dereference a NULL point on
> purpose you need to make it a volatile to conform to the C standard.
> A memory test may want to access address  0, and code that writes the
> ARM or 8086 vector table may also end up dereferencing a NULL
> pointer.
> I think folks will find Chris Lattner's blog interesting

Do you know what MSVC does about this?  For GCC/clang, it is probably
best to add -fno-delete-null-pointer-checks to the command line, because
a NULL pointer dereference will not cause abnormal termination in
TianoCore.  The Linux kernel uses the same option.


Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report.
edk2-devel mailing list