summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Grenville <[email protected]>2012-09-27 22:30:16 +0800
committerRichard Grenville <[email protected]>2012-09-27 22:30:16 +0800
commit4deb30a903f7be941f0aacab25f2ec285e815325 (patch)
tree0208bc900546a89965d3b7586a36def37ad376a8
parent280bc0fc324953e8d2cc14f13e282393a797e4e0 (diff)
downloadtdebase-4deb30a903f7be941f0aacab25f2ec285e815325.tar.gz
tdebase-4deb30a903f7be941f0aacab25f2ec285e815325.zip
Bug fix: Issue #47: Locale cause problems with float arguments
A locale using comma instead of dot in floating point values causes unexpected behavior when parsing floating point commandline arguments. This commits enforces LC_NUMERIC="C" during commandline argument parsing.
-rw-r--r--compton.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/compton.c b/compton.c
index 0b6f2a05a..b9c3e96a1 100644
--- a/compton.c
+++ b/compton.c
@@ -3229,6 +3229,7 @@ get_cfg(int argc, char *const *argv) {
Bool shadow_enable = False, fading_enable = False;
int o, longopt_idx, i;
char *config_file = NULL;
+ char *lc_numeric_old = mstrcpy(setlocale(LC_NUMERIC, NULL));
for (i = 0; i < NUM_WINTYPES; ++i) {
opts.wintype_fade[i] = False;
@@ -3251,6 +3252,11 @@ get_cfg(int argc, char *const *argv) {
#endif
// Parse commandline arguments. Range checking will be done later.
+
+ // Enforce LC_NUMERIC locale "C" here to make sure dots are recognized
+ // instead of commas in atof().
+ setlocale(LC_NUMERIC, "C");
+
optind = 1;
while (-1 !=
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
@@ -3363,6 +3369,10 @@ get_cfg(int argc, char *const *argv) {
}
}
+ // Restore LC_NUMERIC
+ setlocale(LC_NUMERIC, lc_numeric_old);
+ free(lc_numeric_old);
+
// Range checking and option assignments
opts.fade_delta = max_i(opts.fade_delta, 1);
opts.shadow_radius = max_i(opts.shadow_radius, 1);