/src/mozilla-central/tools/fuzzing/common/FuzzingMutate.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "FuzzingMutate.h" |
8 | | #include "FuzzingTraits.h" |
9 | | |
10 | | namespace mozilla { |
11 | | namespace fuzzing { |
12 | | |
13 | | /** |
14 | | * Randomly mutates a byte inside |aData| by using bit manipulation. |
15 | | */ |
16 | | /* static */ |
17 | | void |
18 | | FuzzingMutate::ChangeBit(uint8_t* aData, size_t aLength) |
19 | 0 | { |
20 | 0 | size_t offset = RandomIntegerRange<size_t>(0, aLength); |
21 | 0 | aData[offset] ^= (1 << RandomIntegerRange<unsigned char>(0, 8)); |
22 | 0 | } |
23 | | |
24 | | /** |
25 | | * Randomly replaces a byte inside |aData| with one in the range of [0, 255]. |
26 | | */ |
27 | | /* static */ |
28 | | void |
29 | | FuzzingMutate::ChangeByte(uint8_t* aData, size_t aLength) |
30 | 0 | { |
31 | 0 | size_t offset = RandomIntegerRange<size_t>(0, aLength); |
32 | 0 | aData[offset] = RandomInteger<unsigned char>(); |
33 | 0 | } |
34 | | |
35 | | } // namespace fuzzing |
36 | | } // namespace mozilla |