• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef TEST_FUZZTEST_GETDATA_H
2 #define TEST_FUZZTEST_GETDATA_H
3 
4 /*
5  * Copyright (C) 2023 Huawei Device Co., Ltd.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include <cstdint>
19 
20 #include "../../common/log.h"
21 #include "securec.h"
22 
23 namespace OHOS {
24 namespace NeuralNetworkRuntime {
25 class Data {
26 public:
Data(const uint8_t * data,size_t size)27     Data(const uint8_t* data, size_t size)
28     {
29         dataFuzz = data;
30         dataSize = size;
31     }
32 
GetData()33     template<class T> T GetData()
34     {
35         T object {};
36         size_t objectSize = sizeof(object);
37         if (dataFuzz == nullptr || objectSize > dataSize - dataPos) {
38             LOGE("[GetData]Data is not enough.");
39             return {};
40         }
41         if (memcpy_s(&object, objectSize, dataFuzz + dataPos, objectSize) != EOK) {
42             LOGE("[GetData]Memcpy_s failed.");
43             return {};
44         }
45         dataPos = dataPos + objectSize;
46         return object;
47     }
48 
GetNowData()49     const uint8_t* GetNowData()
50     {
51         return dataFuzz + dataPos;
52     }
53 
GetNowDataSize()54     size_t GetNowDataSize()
55     {
56         return dataSize - dataPos;
57     }
58 private:
59     const uint8_t* dataFuzz {nullptr};
60     size_t dataSize {0};
61     size_t dataPos {0};
62 };
63 } // namespace NeuralNetworkRuntime
64 } // namespace OHOS
65 
66 #endif