From 370f2dda3b723bc9ffb57fe35cdfbd0d814706334602fc991d0f4e86404c86cf Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <jengelh@inai.de>
Date: Wed, 12 May 2021 13:31:44 +0000
Subject: [PATCH] Accepting request 892508 from home:Andreas_Schwab:Factory

- nan-undefined-conversion.patch: ICU-21613 Fix undefined behaviour in
  ComplexUnitsConverter::applyRounder

OBS-URL: https://build.opensuse.org/request/show/892508
OBS-URL: https://build.opensuse.org/package/show/X11:common:Factory/icu?expand=0&rev=149
---
 icu.changes                    |  6 ++++++
 icu.spec                       |  1 +
 nan-undefined-conversion.patch | 20 ++++++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 nan-undefined-conversion.patch

diff --git a/icu.changes b/icu.changes
index 0d722c5..d30fd57 100644
--- a/icu.changes
+++ b/icu.changes
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Wed May 12 08:23:58 UTC 2021 - Andreas Schwab <schwab@suse.de>
+
+- nan-undefined-conversion.patch: ICU-21613 Fix undefined behaviour in
+  ComplexUnitsConverter::applyRounder
+
 -------------------------------------------------------------------
 Sat Apr 10 22:41:04 UTC 2021 - Jan Engelhardt <jengelh@inai.de>
 
diff --git a/icu.spec b/icu.spec
index 74ab5b7..996f7df 100644
--- a/icu.spec
+++ b/icu.spec
@@ -44,6 +44,7 @@ Patch4:         icu-fix-install-mode-files.diff
 Patch6:         icu-error-reporting.diff
 Patch7:         icu-avoid-x87-excess-precision.diff
 Patch8:         locale.diff
+Patch9:         nan-undefined-conversion.patch
 BuildRequires:  fdupes
 BuildRequires:  gcc-c++
 BuildRequires:  pkg-config
diff --git a/nan-undefined-conversion.patch b/nan-undefined-conversion.patch
new file mode 100644
index 0000000..d865fa4
--- /dev/null
+++ b/nan-undefined-conversion.patch
@@ -0,0 +1,20 @@
+From 29f1188d191a7a75ac7ffa4bfa390f625da39c53 Mon Sep 17 00:00:00 2001
+From: Andreas Schwab <schwab@suse.de>
+Date: Tue, 11 May 2021 19:04:24 +0200
+Subject: [PATCH] ICU-21613 Fix undefined behaviour in
+ ComplexUnitsConverter::applyRounder
+
+--- a/source/i18n/units_complexconverter.cpp
++++ b/source/i18n/units_complexconverter.cpp
+@@ -237,6 +237,11 @@ void ComplexUnitsConverter::applyRounder(MaybeStackArray<int64_t, 5> &intValues,
+     }
+     quantity = decimalQuantity.toDouble();
+ 
++    if (uprv_isNaN(quantity) || uprv_isInfinite(quantity)) {
++        // Do nothing for non-finite values, since conversion to int64_t is undefined
++        return;
++    }
++
+     int32_t lastIndex = unitsConverters_.length() - 1;
+     if (lastIndex == 0) {
+         // Only one element, no need to bubble up the carry