1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "span_fuzzer.h"
17 
18 #include "utils/span.h"
19 
20 #include <vector>
21 
22 namespace OHOS {
SpanFuzzTest(const uint8_t* data, size_t size)23     void SpanFuzzTest(const uint8_t* data, size_t size)
24     {
25         const int num = 1;
26 
27         std::vector<uint8_t*> dataVector(size, const_cast<uint8_t*>(data));
28         panda::Span<uint8_t*> instance(dataVector.data(), dataVector.data() + dataVector.size());
29 
30         const std::vector<const uint8_t*> constDataVector(size, data);
31         auto spanInstance = panda::Span(constDataVector);
32         spanInstance.begin();
33         spanInstance.cbegin();
34         spanInstance.end();
35         spanInstance.cend();
36         spanInstance.crbegin();
37         spanInstance.crend();
38         spanInstance[num];
39         spanInstance.Size();
40         spanInstance.Data();
41         spanInstance.First(num);
42         spanInstance.Last(num);
43         spanInstance.SubSpan(num, num);
44         spanInstance.SubSpan(num);
45         spanInstance.size();
46         spanInstance.empty();
47         spanInstance.data();
48     }
49 }
50 
51 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
53 {
54     /* Run your code on data */
55     OHOS::SpanFuzzTest(data, size);
56     return 0;
57 }