The replaced code is a legitimate attempt to index an array based at address zero in x86 real-mode. However, ISO C (both C89 and C99) consider dereferencing a null pointer in this manner to be undefined behavior - which is therefore not portable. Most compilers seem to generate working code for this. Clang 3.8 when compiling with -Os emits a __builtin_trap() into the code with no compile-time diagnostic.
The replacement code calculates the address in a manner such that the possible memory access to address zero is not determinable at compile-time. If the code is instrumented for run-time checks of null, it may still generate an error for accessing the zeroth entry in the array. This sort of instrumentation is not normally used. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zenith432 <zenith...@users.sourceforge.net> --- DuetPkg/BiosVideoThunkDxe/LegacyBiosThunk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DuetPkg/BiosVideoThunkDxe/LegacyBiosThunk.c b/DuetPkg/BiosVideoThunkDxe/LegacyBiosThunk.c index 6dc453f..f11e69a 100644 --- a/DuetPkg/BiosVideoThunkDxe/LegacyBiosThunk.c +++ b/DuetPkg/BiosVideoThunkDxe/LegacyBiosThunk.c @@ -182,8 +182,8 @@ LegacyBiosInt86 ( ThunkRegSet.E.SS = (UINT16) (((UINTN) Stack16 >> 16) << 12); ThunkRegSet.E.ESP = (UINT16) (UINTN) Stack16; - ThunkRegSet.E.Eip = (UINT16)((UINT32 *)NULL)[BiosInt]; - ThunkRegSet.E.CS = (UINT16)(((UINT32 *)NULL)[BiosInt] >> 16); + ThunkRegSet.E.Eip = *(UINT16*)(((UINTN)BiosInt) * sizeof(UINT32)); + ThunkRegSet.E.CS = *(UINT16*)((((UINTN)BiosInt) * sizeof(UINT32)) + sizeof(UINT16)); BiosDev->ThunkContext->RealModeState = &ThunkRegSet; AsmThunk16 (BiosDev->ThunkContext); -- 2.5.5 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel