Skip to content

Commit 6d0488f

Browse files
committed
[compiler-rt] Mark FDP non-template methods inline to avoid ODR violations.
1 parent 9223b7f commit 6d0488f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler-rt/include/fuzzer/FuzzedDataProvider.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ std::vector<T> FuzzedDataProvider::ConsumeRemainingBytes() {
129129
// |.c_str()| on the resulting string is the best way to get an immutable
130130
// null-terminated C string. If fewer than |num_bytes| of data remain, returns
131131
// a shorter std::string containing all of the data that's left.
132-
std::string FuzzedDataProvider::ConsumeBytesAsString(size_t num_bytes) {
132+
inline std::string FuzzedDataProvider::ConsumeBytesAsString(size_t num_bytes) {
133133
static_assert(sizeof(std::string::value_type) == sizeof(uint8_t),
134134
"ConsumeBytesAsString cannot convert the data to a string.");
135135

@@ -144,7 +144,8 @@ std::string FuzzedDataProvider::ConsumeBytesAsString(size_t num_bytes) {
144144
// input data, returns what remains of the input. Designed to be more stable
145145
// with respect to a fuzzer inserting characters than just picking a random
146146
// length and then consuming that many bytes with |ConsumeBytes|.
147-
std::string FuzzedDataProvider::ConsumeRandomLengthString(size_t max_length) {
147+
inline std::string
148+
FuzzedDataProvider::ConsumeRandomLengthString(size_t max_length) {
148149
// Reads bytes from the start of |data_ptr_|. Maps "\\" to "\", and maps "\"
149150
// followed by anything else to the end of the string. As a result of this
150151
// logic, a fuzzer can insert characters into the string, and the string
@@ -172,14 +173,14 @@ std::string FuzzedDataProvider::ConsumeRandomLengthString(size_t max_length) {
172173
}
173174

174175
// Returns a std::string of length from 0 to |remaining_bytes_|.
175-
std::string FuzzedDataProvider::ConsumeRandomLengthString() {
176+
inline std::string FuzzedDataProvider::ConsumeRandomLengthString() {
176177
return ConsumeRandomLengthString(remaining_bytes_);
177178
}
178179

179180
// Returns a std::string containing all remaining bytes of the input data.
180181
// Prefer using |ConsumeRemainingBytes| unless you actually need a std::string
181182
// object.
182-
std::string FuzzedDataProvider::ConsumeRemainingBytesAsString() {
183+
inline std::string FuzzedDataProvider::ConsumeRemainingBytesAsString() {
183184
return ConsumeBytesAsString(remaining_bytes_);
184185
}
185186

@@ -280,7 +281,7 @@ template <typename T> T FuzzedDataProvider::ConsumeProbability() {
280281
}
281282

282283
// Reads one byte and returns a bool, or false when no data remains.
283-
bool FuzzedDataProvider::ConsumeBool() {
284+
inline bool FuzzedDataProvider::ConsumeBool() {
284285
return 1 & ConsumeIntegral<uint8_t>();
285286
}
286287

@@ -315,19 +316,21 @@ T FuzzedDataProvider::PickValueInArray(std::initializer_list<const T> list) {
315316
// In general, it's better to avoid using this function, but it may be useful
316317
// in cases when it's necessary to fill a certain buffer or object with
317318
// fuzzing data.
318-
size_t FuzzedDataProvider::ConsumeData(void *destination, size_t num_bytes) {
319+
inline size_t FuzzedDataProvider::ConsumeData(void *destination,
320+
size_t num_bytes) {
319321
num_bytes = std::min(num_bytes, remaining_bytes_);
320322
CopyAndAdvance(destination, num_bytes);
321323
return num_bytes;
322324
}
323325

324326
// Private methods.
325-
void FuzzedDataProvider::CopyAndAdvance(void *destination, size_t num_bytes) {
327+
inline void FuzzedDataProvider::CopyAndAdvance(void *destination,
328+
size_t num_bytes) {
326329
std::memcpy(destination, data_ptr_, num_bytes);
327330
Advance(num_bytes);
328331
}
329332

330-
void FuzzedDataProvider::Advance(size_t num_bytes) {
333+
inline void FuzzedDataProvider::Advance(size_t num_bytes) {
331334
if (num_bytes > remaining_bytes_)
332335
abort();
333336

0 commit comments

Comments
 (0)