summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-06-19 22:44:08 -0400
committerRich Felker <dalias@aerifal.cx>2012-06-19 22:44:08 -0400
commit85a3ba3a289aa1e0d6cb8ad95f6f358a245a9422 (patch)
treeab405b0c0d0dd99bdad56cf9ec9824ac9d22a14a
parentee96c50d4bac709f02f7007ecf669952d56f1b2d (diff)
downloadmusl-85a3ba3a289aa1e0d6cb8ad95f6f358a245a9422.tar.gz
musl-85a3ba3a289aa1e0d6cb8ad95f6f358a245a9422.tar.bz2
musl-85a3ba3a289aa1e0d6cb8ad95f6f358a245a9422.tar.xz
musl-85a3ba3a289aa1e0d6cb8ad95f6f358a245a9422.zip
fix localeconv values and implementation
dynamic-allocation of the structure is not valid; it can crash an application if malloc fails. since localeconv is not specified to have failure conditions, the object needs to have static storage duration. need to review whether all the values are right or not still..
-rw-r--r--src/locale/localeconv.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/locale/localeconv.c b/src/locale/localeconv.c
index d79d1c07..494cbcc0 100644
--- a/src/locale/localeconv.c
+++ b/src/locale/localeconv.c
@@ -2,21 +2,34 @@
#include <string.h>
#include <stdlib.h>
+static const struct lconv posix_lconv = {
+ .decimal_point = ".",
+ .thousands_sep = "",
+ .grouping = "",
+ .int_curr_symbol = "",
+ .currency_symbol = "",
+ .mon_decimal_point = "",
+ .mon_thousands_sep = "",
+ .mon_grouping = "",
+ .positive_sign = "",
+ .negative_sign = "",
+ .int_frac_digits = -1,
+ .frac_digits = -1,
+ .p_cs_precedes = -1,
+ .p_sep_by_space = -1,
+ .n_cs_precedes = -1,
+ .n_sep_by_space = -1,
+ .p_sign_posn = -1,
+ .n_sign_posn = -1,
+ .int_p_cs_precedes = -1,
+ .int_p_sep_by_space = -1,
+ .int_n_cs_precedes = -1,
+ .int_n_sep_by_space = -1,
+ .int_p_sign_posn = -1,
+ .int_n_sign_posn = -1,
+};
+
struct lconv *localeconv(void)
{
- static struct lconv *posix_lconv;
- if (posix_lconv) return posix_lconv;
- posix_lconv = malloc(sizeof *posix_lconv);
- memset(posix_lconv, -1, sizeof *posix_lconv);
- posix_lconv->decimal_point = ".";
- posix_lconv->thousands_sep = "";
- posix_lconv->grouping = "\xff";
- posix_lconv->int_curr_symbol = ""; //"\xc2\xa4";
- posix_lconv->currency_symbol = "";
- posix_lconv->mon_decimal_point = "";
- posix_lconv->mon_thousands_sep = "";
- posix_lconv->mon_grouping = "\xff";
- posix_lconv->positive_sign = ""; // "+";
- posix_lconv->negative_sign = ""; // "-";
- return posix_lconv;
+ return (void *)&posix_lconv;
}