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