Changeset 13861


Ignore:
Timestamp:
Jan 24, 2013, 4:33:49 PM (8 years ago)
Author:
jordan
Message:

(libT) #5249 'error parsing json in some locales': fix the bug; the new locale unit tests in json-test pass now

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/json-test.c

    r13860 r13861  
    227227  int n;
    228228  int rv;
    229   char lc_numeric[128];
    230   const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
     229
     230  const char * comma_locales[] = { "da_DK.UTF-8",
     231                                   "fr_FR.UTF-8",
     232                                   "ru_RU.UTF-8"};
    231233
    232234  const testFunc tests[] = { test_elements,
     
    238240
    239241  /* run the tests in a locale with a decimal point of '.' */
    240   tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
    241242  setlocale (LC_NUMERIC, "C");
    242243  if ((rv = runTests (tests, NUM_TESTS (tests))))
     
    252253  else if ((rv = runTests (tests, NUM_TESTS(tests))))
    253254    return rv;
    254   setlocale (LC_NUMERIC, lc_numeric);
    255255
    256256  /* success */
  • trunk/libtransmission/variant.c

    r13860 r13861  
    802802  int stackSize = 0;
    803803  int stackAlloc = 64;
    804   char lc_numeric[128];
    805804  struct SaveNode * stack = tr_new (struct SaveNode, stackAlloc);
    806 
    807   /* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
    808   tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
    809   setlocale (LC_NUMERIC, "C");
    810805
    811806  nodeConstruct (&stack[stackSize++], v, sort_dicts);
     
    898893        }
    899894    }
    900 
    901   /* restore the locale... */
    902   setlocale (LC_NUMERIC, lc_numeric);
    903895
    904896  tr_free (stack);
     
    10961088tr_variantToBuf (const tr_variant * v, tr_variant_fmt fmt)
    10971089{
     1090  char lc_numeric[128];
    10981091  struct evbuffer * buf = evbuffer_new();
     1092
     1093  /* parse with LC_NUMERIC="C" to ensure a "." decimal separator */
     1094  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     1095  setlocale (LC_NUMERIC, "C");
    10991096
    11001097  evbuffer_expand (buf, 4096); /* alloc a little memory to start off with */
     
    11151112    }
    11161113
     1114  /* restore the previous locale */
     1115  setlocale (LC_NUMERIC, lc_numeric);
    11171116  return buf;
    11181117}
     
    12621261{
    12631262  int err;
     1263  char lc_numeric[128];
     1264
     1265  /* parse with LC_NUMERIC="C" to ensure a "." decimal separator */
     1266  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     1267  setlocale (LC_NUMERIC, "C");
    12641268
    12651269  switch (fmt)
     
    12751279    }
    12761280
     1281  /* restore the previous locale */
     1282  setlocale (LC_NUMERIC, lc_numeric);
    12771283  return err;
    12781284}
Note: See TracChangeset for help on using the changeset viewer.