Fix another segfault in strtr by adrianheine · Pull Request #6767 · facebook/hhvm


facebook

Article Images

adrianheine

The Wu-Manber implementation in strtr used qsort_r on a collection of
std::strings. 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`.

@facebook-github-bot

@facebook-github-bot

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!

@facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@adrianheine

@Orvid Orvid mentioned this pull request

Jan 29, 2016