MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Sub()
MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Sub()

The subtraction in the assignment

  SignedResult = Minuend - Subtrahend;

is performed with unchecked INT64 operands. According to ISO C, if the
mathematical result of signed integer subtraction cannot be represented in
the result type, the behavior is undefined. (Refer to ISO C99 6.5p5.
6.2.5p9 only exempts unsigned integers, and 6.3.1.3p3 does not apply
because it treats the conversion of integers that have been successfully
evaluated first.)

Replace the after-the-fact result checking with checks on the operands,
and only perform the subtraction if it is safe.

Cc: Bret Barkelew <2f2c66ae900bfc7017ee3c598b548d47eb1001ac@microsoft.com>
Cc: Liming Gao <6480311aeeb4b006862f6d13ebabddc03f51e507@intel.com>
Cc: Michael D Kinney <fd20bc543a9f65bb633fac7d08a403c1f1c8eb6c@intel.com>
Cc: Sean Brogan <45dea30af30ff124e1606962de9a919b96e0e0c6@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <7437296077edea1cb64451c122c4dac071f0cfbc@redhat.com>
Reviewed-by: Ard Biesheuvel <66d3c5fdaeea7ff1f996ad04f2c45e08ab38e2f5@linaro.org>
Tested-by: Michael D Kinney <fd20bc543a9f65bb633fac7d08a403c1f1c8eb6c@intel.com>

MattDevo/edk2,MattDevo/edk2,MattDevo/edk2,MattDevo/edk2,MattDevo/edk2,MattDevo/edk2,MattDevo/edk2,MattDevo/edk2