From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by mx.groups.io with SMTP id smtpd.web11.8630.1602151715404467183 for ; Thu, 08 Oct 2020 03:08:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=sr+AgNNy; spf=pass (domain: akeo.ie, ip: 209.85.218.65, mailfrom: pete@akeo.ie) Received: by mail-ej1-f65.google.com with SMTP id u8so7293420ejg.1 for ; Thu, 08 Oct 2020 03:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZyU2rd74eziuFsRXeS7brzyKSYXs8KT+l+qZ7uC9uf4=; b=sr+AgNNyh2lRNhyDmTcI2OJ1nrlUHKa3FnTE3bcxgMvlWWsfCPDnW07Djog3ROO+Bj E5bkOt/XWmy/Rl7RwdJXxz8v1/YqAxi4Uqb5HPKWBmP7Ql4AvPM9Ii4F0DJGyUUpAJxg 0SPdv1Vj1SGR+qHO8mNzV+0JhZ8QVQC4pdoloQ5HXBYaERtH+91E/ySRk0i1P4yHEqOR LH+N2slUUhMjV5zASfeq8h55bdG5v4ugs+0UgOfhtir6KDR12Hp3hKNJJal5v9Sde4XN yqgrJ2M65iXI7t4YIVkhJHE9ePjwC6bYpo39NEmKO+h7cUZJINQCiqLoCyRvEdVvM40o MpbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZyU2rd74eziuFsRXeS7brzyKSYXs8KT+l+qZ7uC9uf4=; b=nOTbxMsxvZypW29tqLYhLjGzDkoIQhs7p51wPYI5d0bhsZFkoLfNtHVYetpDIp6Fzo mQw0v+Q717KBrIk2AaRwjGkxFPfOynHSpMl7Gef9kcI0fVWENRWWoh6T4RdbQYEEaMU5 Bs3Wl9Dzizy7Lbj4pMlxoEPdxSxg0vXsmGYk2dfVmWj8FR7R/LIZVQl9toL5GQBjJKVL WrwO3QeMb2wp8bvQ2KaDuWX6oZTBZyQjqw8vkivmTNKP6QYjIgSBI1/3GtisgOhPemfY Tgoc4jivVim6XHUK3OcA+/f6MDCymF4nkFu/NoYiZs481nj6ccXNpTXOZ+MqYVp4w0Ez AQ6w== X-Gm-Message-State: AOAM530zqLe5wjr9fv6DF+8kCM/Urs0X8pm0HjMAV+iJLgp3fMwC+YLH 6HCN1irNLnITHAEFhwJ7cwtU1YahV6pISV+d X-Google-Smtp-Source: ABdhPJyrjtcVLabwTyTqRzAwT2IvDwiBTp8P2Za/CLmxG2SCoRF8hQZhQUoVOpGr97X5biyYvox9xw== X-Received: by 2002:a17:906:fcae:: with SMTP id qw14mr8152478ejb.537.1602151713556; Thu, 08 Oct 2020 03:08:33 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.64.41]) by smtp.gmail.com with ESMTPSA id n22sm3646529eji.106.2020.10.08.03.08.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 03:08:32 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com Subject: [PATCH 1/1] EmbeddedPkgLibrary/VirtualRealTimeClockLib: Explicit cast to UINT32 Date: Thu, 8 Oct 2020 11:08:21 +0100 Message-Id: <20201008100821.14780-1-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Addresses BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2380 where explicit casts are required for 64 to 32 bit assignment. We can apply a straight cast for Time->Nanosecond since we already checked for overflow. On the other hand, we may have a frequency that is greater than UINT32_MAX for Capabilities->Resolution. But using the frequency for the resolution is the wrong approach anyway, since we can't actually vouch for the actual resolution of the virtual library. Instead, play it safe by defaulting to 1 Hz, which is what a standard PC-AT CMOS RTC device would use. Signed-off-by: Pete Batard --- EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c index 74e72bd48b4c..5c13ed4cf190 100644 --- a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c @@ -202,14 +202,14 @@ LibGetTime ( // Because we use the performance counter, we can fill the Nanosecond attribute // provided that the remainder doesn't overflow 64-bit during multiplication. if (Remainder <= 18446744073U) { - Time->Nanosecond = MultU64x64 (Remainder, 1000000000U) / Freq; + Time->Nanosecond = (UINT32)(MultU64x64 (Remainder, 1000000000U) / Freq); } else { DEBUG ((DEBUG_WARN, "LibGetTime: Nanosecond value not set (64-bit overflow).\n")); } if (Capabilities) { Capabilities->Accuracy = 0; - Capabilities->Resolution = Freq; + Capabilities->Resolution = 1; Capabilities->SetsToZero = FALSE; } -- 2.21.0.windows.1