MdeModulePkg: Use unsigned memory type bounds checks

Some compilers treat EFI_MEMORY_TYPE as signed. OS-reserved memory
types with bit 31 set can therefore pass a signed comparison against
EfiMaxMemoryType and index outside the memory type statistics array.

Cast the memory type to UINT32 before checking the array bound in
CoreTerminateMemoryMap and InternalBuildMemoryAllocationHob, matching
the existing guards in the page, pool, and memory bin code.

Fixes: https://github.com/tianocore/edk2/issues/13451
Signed-off-by: Mattia Giambirtone <nocturn9x@nocturn9x.space>
2 files changed