MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / setBytes

Method setBytes

include/runtime/instance/memory.h:157–181  ·  view source on GitHub ↗

Replace the bytes of Data[Offset :] by Slice[Start : Start + Length - 1]

Source from the content-addressed store, hash-verified

155
156 /// Replace the bytes of Data[Offset :] by Slice[Start : Start + Length - 1]
157 Expect<void> setBytes(Span<const Byte> Slice, const uint64_t Offset,
158 const uint64_t Start, const uint64_t Length) noexcept {
159 // Check the memory boundary.
160 if (unlikely(!checkAccessBound(Offset, Length))) {
161 spdlog::error(ErrCode::Value::MemoryOutOfBounds);
162 spdlog::error(ErrInfo::InfoBoundary(Offset, Length, getSize()));
163 return Unexpect(ErrCode::Value::MemoryOutOfBounds);
164 }
165
166 // Check the input data validation.
167 if (unlikely(std::numeric_limits<uint64_t>::max() - Start < Length ||
168 Start + Length > static_cast<uint64_t>(Slice.size()))) {
169 spdlog::error(ErrCode::Value::MemoryOutOfBounds);
170 spdlog::error(ErrInfo::InfoBoundary(Start, Length,
171 static_cast<uint64_t>(Slice.size())));
172 return Unexpect(ErrCode::Value::MemoryOutOfBounds);
173 }
174
175 // Copy the data.
176 if (likely(Length > 0)) {
177 std::copy(Slice.begin() + Start, Slice.begin() + Start + Length,
178 DataPtr + Offset);
179 }
180 return {};
181 }
182
183 /// Fill the bytes of Data[Offset : Offset + Length - 1] by Val.
184 Expect<void> fillBytes(const uint8_t Val, const uint64_t Offset,

Callers 7

initMemoryMethod · 0.80
convValsToCoreWASMMethod · 0.80
runMemoryInitOpMethod · 0.80
runMemoryCopyOpMethod · 0.80
proxyMemInitMethod · 0.80
proxyMemCopyMethod · 0.80

Calls 7

unlikelyFunction · 0.85
InfoBoundaryClass · 0.85
UnexpectFunction · 0.85
errorFunction · 0.50
likelyFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected