Bug 1261692 - MODIFICATION_FAILED error when decimal separator is comma;r+a=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sun, 01 May 2016 19:28:49 +0200
changeset 24868 22ffea29a85d33082ff1dee3e7ba35b9a66968ec
parent 24867 d27e0d778376e4d117c869124df897a838b007e5
child 24869 57c80e50a92293e8f9d630fb50bf9c184039bf16
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1261692
Bug 1261692 - MODIFICATION_FAILED error when decimal separator is comma;r+a=philipp make sure snprintf uses the "C" locale when printing floating point numbers thanks for the patch Christophe! Backport of upstream commit https://github.com/libical/libical/commit/d3623d1f5a9ef3be16bd32e117c0d96f1f9626d2
calendar/libical/src/libical/icalvalue.c
--- a/calendar/libical/src/libical/icalvalue.c
+++ b/calendar/libical/src/libical/icalvalue.c
@@ -1037,39 +1037,61 @@ static char* icalvalue_datetime_as_ical_
     return str;
 
 }
 
 static char* icalvalue_float_as_ical_string_r(const icalvalue* value) {
 
     float data;
     char* str;
+    char* old_locale;
     icalerror_check_arg_rz( (value!=0),"value");
     data = icalvalue_get_float(value);
 
+    /* bypass current locale in order to make
+       sure snprintf uses a '.' as a separator
+       set locate to 'C' and keep old locale */
+    old_locale = strdup (setlocale (LC_NUMERIC,NULL));
+    setlocale (LC_NUMERIC,"C");
+
     str = (char*)icalmemory_new_buffer(40);
 
     snprintf(str,40,"%f",data);
 
+    /* restore saved locale */
+    setlocale (LC_NUMERIC,old_locale);
+    free (old_locale);
+
     return str;
 }
 
 
 static char* icalvalue_geo_as_ical_string_r(const icalvalue* value) {
 
     struct icalgeotype data;
     char* str;
+    char* old_locale;
     icalerror_check_arg_rz( (value!=0),"value");
 
     data = icalvalue_get_geo(value);
 
+    /* bypass current locale in order to make
+     * sure snprintf uses a '.' as a separator
+     * set locate to 'C' and keep old locale */
+    old_locale = strdup (setlocale (LC_NUMERIC,NULL));
+    setlocale (LC_NUMERIC,"C");
+
     str = (char*)icalmemory_new_buffer(80);
 
     snprintf(str,80,"%f;%f",data.lat,data.lon);
 
+    /* restore saved locale */
+    setlocale (LC_NUMERIC,old_locale);
+    free (old_locale);
+
     return str;
 }
 
 
 static char* icalvalue_datetimeperiod_as_ical_string_r(const icalvalue* value) {
     struct icaldatetimeperiodtype dtp = icalvalue_get_datetimeperiod(value);
 
     icalerror_check_arg_rz( (value!=0),"value");