From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-x244.google.com (mail-ua0-x244.google.com [IPv6:2607:f8b0:400c:c08::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C510321A16EC2 for ; Tue, 16 May 2017 05:10:44 -0700 (PDT) Received: by mail-ua0-x244.google.com with SMTP id x47so9520389uab.0 for ; Tue, 16 May 2017 05:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=mBU/s3y2n+PQTl/xJyYz2wJga64qK9Lsoy4UvmUoCnM=; b=lSLaEHeKwhZ9X+8cNXWVLRx3Uo4FiLfXXucPfqjval5YdDmMgdnrU7g9JbavkPxrnF ZNqAr71wjt6gf8K0sY1yP1OPiG2e/lZCU3XxQjhB3o7GcXIk4hJCgyJSE06pQv9SDczI V6v0jCwVQBuNHsKX4tTTlyefDt51HWRLL2Pzsb8UDt+FvJK5ZkyGwBgjYK0C4z1Jrc5j pgY/aD6OTuffwBKcCm/9EKHNVknBbOy5GEX2Vzh5rO943c1gr7vZfgi9ifu6EM9VRmEF hYbQeBIigYAbCMDf+IYV6z3FA/wkkr3POm00HX7I6huVwihH4xMZwHGTM8ZWyYv40LVP 1Rlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=mBU/s3y2n+PQTl/xJyYz2wJga64qK9Lsoy4UvmUoCnM=; b=Bey1Bc52hvt/JBlwjyDdtVO785+jREM/XjzBasWtx5lWSw+9kB5Uvn2/qBLXWfAPpW bzysguF02guptHl/5JI290n22A1FS3E+DTzcG4n0Zr/GXKyDb02RvFzNpqdXu/HHAPpi XKz4gqzZlpG0WeUtILzzJ8Zui4JUwBUeipH5QuvjTBRJCTTmY1MBFIXNbcvG7hit0Zo0 Ex9mXbqCE3PD3qwMajaRGPXTdnJNAPR/9PBuUtgQFXXTpjVVY4LyOk5AYgDenytQWYdE 2pqaQQ+ObYdYrlBngMpFyABrFQvCzaqsBOwE/Ax+44fFc9yWNlA3oOnjVfPlgLuRzVDa zRwA== X-Gm-Message-State: AODbwcCbXX5ycqMYuPpk1wdpHFWpMSuFPTH5zExwPWL6AxkQtA4eWc2W KvQlMfiax9oAnceZ0kMuzQqMAa/RhQ== X-Received: by 10.176.91.20 with SMTP id u20mr5736376uae.138.1494936643677; Tue, 16 May 2017 05:10:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.159.35.78 with HTTP; Tue, 16 May 2017 05:10:43 -0700 (PDT) In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14D72E8BC@shsmsx102.ccr.corp.intel.com> References: <1494903391-716-1-git-send-email-s.temerkhanov@gmail.com> <1494903391-716-2-git-send-email-s.temerkhanov@gmail.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14D72E8BC@shsmsx102.ccr.corp.intel.com> From: Sergei Temerkhanov Date: Tue, 16 May 2017 15:10:43 +0300 Message-ID: To: "Gao, Liming" Cc: "edk2-devel@lists.01.org" Subject: Re: [PATCH] MdePkg: Fix undefined behavior on variadic parameters X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 May 2017 12:10:45 -0000 Content-Type: text/plain; charset="UTF-8" On Tue, May 16, 2017 at 8:10 AM, Gao, Liming wrote: > Sergey: > Could you give more detail on the undefined behavior on variadic parameters? > > I see https://bugzilla.tianocore.org/show_bug.cgi?id=410 describe this issues found in the latest CLANG tool chain. Do you find other tool chain reports it? Yes, this is exactly the bug this patch fixes. As per the C99 standard: "The parameter parmN is the identifier of the rightmost parameter in the variable parameter list in the function definition (the one just before the , ...). If the parameter parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default argument promotions, the behavior is undefined." That's exactly the case here since BOOLEAN is a typedef for unsigned char. It undergoes a promotion to an unsigned int which is not a compatible type for unsigned char. Correct me if I'm wrong. Regards, Sergey > > Thanks > Liming >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Sergey Temerkhanov >> Sent: Tuesday, May 16, 2017 10:57 AM >> To: edk2-devel@lists.01.org >> Subject: [edk2] [PATCH] MdePkg: Fix undefined behavior on variadic parameters >> >> Fix undefined behavior by avoiding parameter type promotion >> >> Signed-off-by: Sergey Temerkhanov >> --- >> MdePkg/Include/Library/UefiLib.h | 2 +- >> MdePkg/Library/UefiLib/UefiLib.c | 2 +- >> 2 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h >> index 0b14792..4e4697c 100644 >> --- a/MdePkg/Include/Library/UefiLib.h >> +++ b/MdePkg/Include/Library/UefiLib.h >> @@ -818,7 +818,7 @@ CHAR8 * >> EFIAPI >> GetBestLanguage ( >> IN CONST CHAR8 *SupportedLanguages, >> - IN BOOLEAN Iso639Language, >> + IN UINTN Iso639Language, >> ... >> ); >> >> diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c >> index a7eee01..74528ec 100644 >> --- a/MdePkg/Library/UefiLib/UefiLib.c >> +++ b/MdePkg/Library/UefiLib/UefiLib.c >> @@ -1514,7 +1514,7 @@ CHAR8 * >> EFIAPI >> GetBestLanguage ( >> IN CONST CHAR8 *SupportedLanguages, >> - IN BOOLEAN Iso639Language, >> + IN UINTN Iso639Language, >> ... >> ) >> { >> -- >> 2.7.4 >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel