Skip to content

Commit

Permalink
Bug fix: Issue tryone144#47: Locale cause problems with float arguments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richardgv committed Sep 27, 2012
1 parent 75ebe94 commit 69513d6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 69513d6

Please sign in to comment.