From 6625a75eac0d738566b3c38f7110c4a35afa4b98 Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 8 Sep 2010 12:15:13 +0000 Subject: [PATCH] fix use of setlocale all over the place ... - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); the original version never restored the locale since it held a copy of the new locale and not the old one despite the name. bug found by Pawe? 'Reef' Polewicz git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3/program@2127 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_create.c | 3 ++- src/rrd_dump.c | 3 ++- src/rrd_graph.c | 6 ++++++ src/rrd_rpncalc.c | 3 ++- src/rrd_tool.c | 3 ++- src/rrd_tune.c | 9 ++++++--- src/rrd_update.c | 9 ++++++--- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/rrd_create.c b/src/rrd_create.c index 4e98d53..d9fd6ff 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -574,7 +574,8 @@ void parseGENERIC_DS( &(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr,maxstr); */ - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if (sscanf(def, "%lu:%18[^:]:%18[^:]", &(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr, maxstr) == 3) { diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 226f5ec..de037b8 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -90,7 +90,8 @@ int rrd_dump_opt_r( out_file = stdout; } #ifdef HAVE_SETLOCALE - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); #endif if (!opt_noheader) { fputs("\n", out_file); diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 022ca27..dcc2024 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -3706,15 +3706,19 @@ rrd_info_t *rrd_graph_v( rrd_info_t *grinfo; rrd_graph_init(&im); /* a dummy surface so that we can measure text sizes for placements */ + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); rrd_graph_options(argc, argv, &im); if (rrd_test_error()) { + setlocale(LC_NUMERIC, old_locale); /* reenable locale */ rrd_info_free(im.grinfo); im_free(&im); return NULL; } if (optind >= argc) { + setlocale(LC_NUMERIC, old_locale); /* reenable locale */ rrd_info_free(im.grinfo); im_free(&im); rrd_set_error("missing filename"); @@ -3722,6 +3726,7 @@ rrd_info_t *rrd_graph_v( } if (strlen(argv[optind]) >= MAXPATH) { + setlocale(LC_NUMERIC, old_locale); /* reenable locale */ rrd_set_error("filename (including path) too long"); rrd_info_free(im.grinfo); im_free(&im); @@ -3736,6 +3741,7 @@ rrd_info_t *rrd_graph_v( } rrd_graph_script(argc, argv, &im, 1); + setlocale(LC_NUMERIC, old_locale); /* reenable locale */ if (rrd_test_error()) { rrd_info_free(im.grinfo); im_free(&im); diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index d46de80..e4b224d 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -297,7 +297,8 @@ rpnp_t *rpn_parse( char vname[MAX_VNAME_LEN + 10]; char *old_locale; - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); rpnp = NULL; expr = (char *) expr_const; diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 4549073..8fe46a2 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -718,7 +718,8 @@ int HandleInputLine( if (rrd_xport (argc - 1, &argv[1], &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data) != -1) { - char *old_locale = setlocale(LC_NUMERIC, "C"); + char *old_locale = setlocale(LC_NUMERIC,NULL); + setlocale(LC_NUMERIC, "C"); row_cnt = (end - start) / step; ptr = data; printf("\n\n", diff --git a/src/rrd_tune.c b/src/rrd_tune.c index 55aff3d..1d78380 100644 --- a/src/rrd_tune.c +++ b/src/rrd_tune.c @@ -121,7 +121,8 @@ int rrd_tune( optcnt++; switch (opt) { case 'h': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if ((matches = sscanf(optarg, DS_NAM_FMT ":%ld", ds_nam, &heartbeat)) != 2) { @@ -141,7 +142,8 @@ int rrd_tune( break; case 'i': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if ((matches = sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) { rrd_set_error("invalid arguments for minimum ds value"); @@ -163,7 +165,8 @@ int rrd_tune( break; case 'a': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if ((matches = sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) { rrd_set_error("invalid arguments for maximum ds value"); diff --git a/src/rrd_update.c b/src/rrd_update.c index 200f412..6e15b08 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -946,7 +946,8 @@ static int get_time_from_reading( *current_time = tmp_time.tv_sec; *current_time_usec = tmp_time.tv_usec; } else { - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; tmp = strtod(updvals[0], 0); if (errno > 0) { @@ -1058,7 +1059,8 @@ static int update_pdp_prep( } break; case DST_ABSOLUTE: - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; pdp_new[ds_idx] = strtod(updvals[ds_idx + 1], &endptr); if (errno > 0) { @@ -1076,7 +1078,8 @@ static int update_pdp_prep( rate = pdp_new[ds_idx] / interval; break; case DST_GAUGE: - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; pdp_new[ds_idx] = strtod(updvals[ds_idx + 1], &endptr) * interval; -- 2.30.2