refactor: remove usage of locale dependent std::isspace #14585

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:no-locale-surprises-please changing 6 files +25 −13
  1. practicalswift commented at 5:00 pm on October 26, 2018: contributor

    Don’t rely on locale dependent function std::isspace in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...).

    Rationale:

     0$ uname -s
     1Darwin
     2$ cat poc.cpp
     3#include <iostream>
     4#include <locale>
     5
     6int main(void) {
     7    setlocale(LC_ALL, "");
     8    std::cout << std::isspace(133) << ' ' << std::isspace(154) << ' ' << std::isspace(160);
     9    std::cout << '\n';
    10}
    11$ clang++ -o poc poc.cpp
    12$ ./poc
    131 0 1
    14$ LC_ALL=en_US ./poc
    151 0 1
    16$ LC_ALL=C ./poc
    170 0 0
    18$ LC_ALL=ru_RU.KOI8-R ./poc # an "interesting" locale
    190 1 0
    
  2. practicalswift force-pushed on Oct 26, 2018
  3. DrahtBot commented at 5:17 pm on October 26, 2018: member
    • #14555 (Move util files to directory by jimpo)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. practicalswift force-pushed on Oct 26, 2018
  5. practicalswift force-pushed on Oct 26, 2018
  6. Don't rely on locale dependent functions in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...) 15db77f4dd
  7. practicalswift force-pushed on Oct 26, 2018
  8. sipa commented at 5:52 pm on October 26, 2018: member
    utACK 15db77f4dd7f1a7963398f1576580b577a1697bc
  9. MarcoFalke commented at 8:01 pm on October 26, 2018: member
    utACK 15db77f
  10. fanquake added the label Refactoring on Oct 26, 2018
  11. in src/utilstrencodings.h:85 in 15db77f4dd
    80+ * same result as std::isspace.
    81+ *
    82+ * @param[in] c     character to test
    83+ * @return          true if the argument is a whitespace character; otherwise false
    84+ */
    85+constexpr inline bool IsSpace(char c) noexcept {
    


    Empact commented at 4:48 pm on October 27, 2018:
  12. in src/utilstrencodings.h:80 in 15db77f4dd
    75+ * Tests if the given character is a whitespace character. The whitespace characters
    76+ * are: space, form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal
    77+ * tab ('\t'), and vertical tab ('\v').
    78+ *
    79+ * This function is locale independent. Under the C locale this function gives the
    80+ * same result as std::isspace.
    


    Empact commented at 4:50 pm on October 27, 2018:
    nit: Could be more clear: “, giving the same result as std::isspace does under the C locale.”
  13. Empact commented at 4:51 pm on October 27, 2018: member
    Could include a test comparing its output to std::isspace
  14. Empact commented at 4:51 pm on October 27, 2018: member
    utACK 15db77f
  15. fanquake renamed this:
    Don't rely on locale dependent functions in base_blob<BITS>::SetHex(...) (uint256), DecodeBase58(...), ParseMoney(...) and ParseHex(...)
    refactor: remove usage of locale dependent std::isspace
    on Oct 28, 2018
  16. fanquake commented at 2:40 am on October 28, 2018: member

    ACK 15db77f

    Tested the same poc, other interesting locales:

    0LC_ALL=it_IT.ISO8859-15 ./poc
    10 0 1
    2LC_ALL=uk_UA.KOI8-U ./poc
    30 1 0
    4LC_ALL=hu_HU.ISO8859-2 ./poc
    50 0 1
    
  17. pull[bot] referenced this in commit f1e2f2a859 on Oct 28, 2018
  18. MarcoFalke merged this on Oct 28, 2018
  19. MarcoFalke closed this on Oct 28, 2018

  20. fanquake deleted a comment on Nov 21, 2018
  21. practicalswift deleted the branch on Apr 10, 2021
  22. Munkybooty referenced this in commit aa0b72952d on Jul 22, 2021
  23. Munkybooty referenced this in commit 811dc19d3f on Jul 22, 2021
  24. Munkybooty referenced this in commit 3dfc8bc418 on Jul 23, 2021
  25. Munkybooty referenced this in commit a3245db8a7 on Jul 23, 2021
  26. PastaPastaPasta referenced this in commit cdd53d489e on Aug 16, 2021
  27. vijaydasmp referenced this in commit ed879057b1 on Sep 8, 2021
  28. vijaydasmp referenced this in commit 20b2940170 on Sep 8, 2021
  29. vijaydasmp referenced this in commit 75cfa2afdc on Sep 8, 2021
  30. vijaydasmp referenced this in commit aca7b80fc4 on Sep 9, 2021
  31. vijaydasmp referenced this in commit c97bb0e63b on Sep 9, 2021
  32. vijaydasmp referenced this in commit 208bb4989d on Sep 9, 2021
  33. dzutto referenced this in commit 6bb5dfe2d9 on Sep 9, 2021
  34. UdjinM6 referenced this in commit be2bd03370 on Sep 9, 2021
  35. gades referenced this in commit 81c628e4ed on May 9, 2022
  36. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me