Fix another segfault in strtr by adrianheine · Pull Request #6767 · facebook/hhvm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
The Wu-Manber implementation in strtr
used qsort_r
on a collection of
std::string
s. However, the C++ standard clearly says that qsort
's behavior
is undefined with non-trivial collection elements. std::string
is not
trivial. While qsort_r
is not part of the C++ standard, it's behavior should
not be expected to be defined with non-trivial types either.
See http://en.cppreference.com/w/cpp/algorithm/qsort
This change replaces qsort_r
usage with std::sort
.
The Wu-Manber implementation in `strtr` used `qsort_r` on a collection of `std::string`s. However, the C++ standard clearly says that `qsort`'s behavior is undefined with non-trivial collection elements. `std::string` is not trivial. While `qsort_r` is not part of the C++ standard, it's behavior should not be expected to be defined with non-trivial types either. See http://en.cppreference.com/w/cpp/algorithm/qsort This change replaces `qsort_r` usage with `std::sort`.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!
Orvid mentioned this pull request