Memcpy a struct in storage_var

let (result : ERC721PUT*) = alloc()
let (local _bid : ERC721PUT) = bids.read(bid_index)
memcpy(result, &_bid, ERC721PUT.SIZE) curious why this will not work? is &_bid not appropriate here ?

bids is a storage_var

I get this \nUnknown value for memory cell at address 12:12.\n assert [frame.dst] = [frame.src]\n

13 Likes

Last time I had this error it was linked to the fact that the size was uncorrect.
I think this question would be answered more quickly on the discord :slight_smile:

8 Likes

Just to complete the circle for anybody else. I was returning from a function the array where the result_len was based on felt and not on ERC721PUT

return (result_len, result) โ† result_len was the problem.

Thanks Gaetbout

6 Likes

This doesnโ€™t work because &_bid refers to a local variable in memory, not a storage reference. bids.read(bid_index) loads the value into memory, but memcpy expects both source and destination to be valid memory addresses. _bid is a value, not a pointer. You canโ€™t take its address like that. Instead, write each field manually or load directly into result.