93dc2d
commit 1d8e3a2c6636cf0b1b8fa2f869cef6ec10726933
93dc2d
Author: Carlos O'Donell <carlos@redhat.com>
93dc2d
Date:   Mon Jan 31 00:34:41 2022 -0500
93dc2d
93dc2d
    localedef: Fix handling of empty mon_decimal_point (Bug 28847)
93dc2d
    
93dc2d
    The handling of mon_decimal_point is incorrect when it comes to
93dc2d
    handling the empty "" value.  The existing parser in monetary_read()
93dc2d
    will correctly handle setting the non-wide-character value and the
93dc2d
    wide-character value e.g. STR_ELEM_WC(mon_decimal_point) if they are
93dc2d
    set in the locale definition.  However, in monetary_finish() we have
93dc2d
    conflicting TEST_ELEM() which sets a default value (if the locale
93dc2d
    definition doesn't include one), and subsequent code which looks for
93dc2d
    mon_decimal_point to be NULL to issue a specific error message and set
93dc2d
    the defaults. The latter is unused because TEST_ELEM() always sets a
93dc2d
    default.  The simplest solution is to remove the TEST_ELEM() check,
93dc2d
    and allow the existing check to look to see if mon_decimal_point is
93dc2d
    NULL and set an appropriate default.  The final fix is to move the
93dc2d
    setting of mon_decimal_point_wc so it occurs only when
93dc2d
    mon_decimal_point is being set to a default, keeping both values
93dc2d
    consistent. There is no way to tell the difference between
93dc2d
    mon_decimal_point_wc having been set to the empty string and not
93dc2d
    having been defined at all, for that distinction we must use
93dc2d
    mon_decimal_point being NULL or "", and so we must logically set
93dc2d
    the default together with mon_decimal_point.
93dc2d
    
93dc2d
    Lastly, there are more fixes similar to this that could be made to
93dc2d
    ld-monetary.c, but we avoid that in order to fix just the code
93dc2d
    required for mon_decimal_point, which impacts the ability for C.UTF-8
93dc2d
    to set mon_decimal_point to "", since without this fix we end up with
93dc2d
    an inconsistent setting of mon_decimal_point set to "", but
93dc2d
    mon_decimal_point_wc set to "." which is incorrect.
93dc2d
    
93dc2d
    Tested on x86_64 and i686 without regression.
93dc2d
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
93dc2d
93dc2d
diff --git a/locale/programs/ld-monetary.c b/locale/programs/ld-monetary.c
93dc2d
index e1e45a3409123bf4..9b9a55bb4766dfcf 100644
93dc2d
--- a/locale/programs/ld-monetary.c
93dc2d
+++ b/locale/programs/ld-monetary.c
93dc2d
@@ -208,7 +208,6 @@ No definition for %s category found"), "LC_MONETARY");
93dc2d
 
93dc2d
   TEST_ELEM (int_curr_symbol, "");
93dc2d
   TEST_ELEM (currency_symbol, "");
93dc2d
-  TEST_ELEM (mon_decimal_point, ".");
93dc2d
   TEST_ELEM (mon_thousands_sep, "");
93dc2d
   TEST_ELEM (positive_sign, "");
93dc2d
   TEST_ELEM (negative_sign, "");
93dc2d
@@ -258,6 +257,7 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"),
93dc2d
 	record_error (0, 0, _("%s: field `%s' not defined"),
93dc2d
 		      "LC_MONETARY", "mon_decimal_point");
93dc2d
       monetary->mon_decimal_point = ".";
93dc2d
+      monetary->mon_decimal_point_wc = L'.';
93dc2d
     }
93dc2d
   else if (monetary->mon_decimal_point[0] == '\0' && ! be_quiet && ! nothing)
93dc2d
     {
93dc2d
@@ -265,8 +265,6 @@ not correspond to a valid name in ISO 4217 [--no-warnings=intcurrsym]"),
93dc2d
 %s: value for field `%s' must not be an empty string"),
93dc2d
 		    "LC_MONETARY", "mon_decimal_point");
93dc2d
     }
93dc2d
-  if (monetary->mon_decimal_point_wc == L'\0')
93dc2d
-    monetary->mon_decimal_point_wc = L'.';
93dc2d
 
93dc2d
   if (monetary->mon_grouping_len == 0)
93dc2d
     {