Do not use small category in fbstring when in ASan mode
authorGiuseppe Ottaviano <ott@fb.com>
Wed, 30 Mar 2016 23:39:11 +0000 (16:39 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Wed, 30 Mar 2016 23:50:28 +0000 (16:50 -0700)
commitef01f57b5f0f659b6bfd3fe3ce05f2b678ac750a
tree46705ab16cdc8c82745cf9dff574cd8f76c6b63f
parentebf930ca4820e44b33b5772260e78c6baab17604
Do not use small category in fbstring when in ASan mode

Summary:`fbstring`'s small string optimization prevents ASan to catch invalid
accesses to the data of a destroyed string, for example if a
`StringPiece` is initialized from a temporary string.

This diff disables building a string with the small category when
compiled with ASan: small strings will be constructed as
`Medium`-category strings and heap-allocated. This is done by only
changing the behavior of construction and resizing, so that the ABI is
preserved and it is still possible to link an ASan-enabled object file
with a library that wasn't compiled with ASan.

The diff also fixes a blind spot in `fbstring_core`'s constructor,
which disabled ASan altogether in order to allow fast word-aligned
copy of small strings. Since small string construction is now disabled
under ASan, we don't need to disable it anymore.

Lastly, it always clears moved-from strings, even when they are small.
This improves the performance of the move constructor (no more conditional
needed) and it uncovers another class of potential bugs.

Reviewed By: luciang

Differential Revision: D3114022

fb-gh-sync-id: 4e180fbf2b8aced3b977afc985d26fdf244d9598
fbshipit-source-id: 4e180fbf2b8aced3b977afc985d26fdf244d9598
folly/FBString.h