forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pulse] model some of
std::basic_string
Summary: A common gotcha is the new test. Model the minimum amount of `std::basic_string` to catch it. Reviewed By: mbouaziz, ngorogiannis Differential Revision: D16121090 fbshipit-source-id: 66f06cb43
- Loading branch information
1 parent
14b9975
commit a504a67
Showing
3 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
#include <string> | ||
|
||
// inspired by folly::Range | ||
struct Range { | ||
const char *b_, *e_; | ||
|
||
Range(const std::string& str) : b_(str.data()), e_(b_ + str.size()) {} | ||
|
||
char operator[](size_t i) { return b_[i]; } | ||
}; | ||
|
||
const Range setLanguage(const std::string& s) { | ||
return s[0] == 'k' ? s.substr(0, 1) // cast to Range returns pointers | ||
// into stack-allocated temporary string | ||
: "en"; | ||
} | ||
|
||
bool use_range_of_invalidated_temporary_string_bad(const std::string& str) { | ||
auto s = setLanguage(str); | ||
return s[0] == 'k'; | ||
} |
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