Fix another segfault in strtr
commit1a236378cdd8cc5e1a9912ad6ae93969c5c0c262
authorAdrian Heine <adrian.heine@wikimedia.de>
Tue, 2 Feb 2016 19:21:01 +0000 (2 11:21 -0800)
committerhhvm-bot <hhvm-bot@fb.com>
Tue, 2 Feb 2016 19:30:47 +0000 (2 11:30 -0800)
treef1a1bcaeb2ac2dc266a8fda1a6018c9cfb8de017
parenta101a811c99dd86b260609dd2b30c368a846bfbb
Fix another segfault in strtr

Summary:
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`.
Closes https://github.com/facebook/hhvm/pull/6767

Reviewed By: sgolemon, JoelMarcey

Differential Revision: D2843994

Pulled By: sgolemon

fb-gh-sync-id: c3b84b34156b7cf3202ea9176bd6873da5056f92
hphp/runtime/ext/string/ext_string.cpp
hphp/test/slow/string/strtr_segfault2.php [new file with mode: 0644]
hphp/test/slow/string/strtr_segfault2.php.expect [new file with mode: 0644]