Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Document how to properly use multi_index::get and deprecate related methods that take a reference #818

Closed
arhag opened this issue Jun 19, 2018 · 4 comments · Fixed by #1023
Assignees
Labels
documentation Documentation related edits, non-breaking only

Comments

@arhag
Copy link
Contributor

arhag commented Jun 19, 2018

We need clear documentation on how to use multi_index::get so that contract developers avoid the common pitfall of copy assigning the reference returned from multi_index::get to a stack-allocated local variable and then passing that into multi_index::modify.

The most common mistake is that users use auto as the typename for the local variable when they should be using auto& or decltype(auto).

Also, because this is a common mistake contract developers make which could lead to undefined behavior, we should deprecate the overloads of modify and erase methods in multi_index that take a reference, and encourage them to use the versions that take const_iterator instead which are much safer.

We should also provide warnings in the documentation about using iterator_to which can have similar undefined behavior if the developer passes in a reference to a stack-allocated object rather than the reference returned by get or by dereferencing a const_iterator. Perhaps we can also provide a safer overload of iterator_to that takes a const_iterator.

Along with deprecating multi_index::get, we should also make sure we do not actually use it in any of the contracts in our repository. Instead we could use multi_index::require_find from EOSIO/eos#4227.

@arhag arhag changed the title Document how to properly use multi_index::get and deprecate it Document how to properly use multi_index::get and deprecate related methods that take a reference Jun 19, 2018
@dixia
Copy link
Contributor

dixia commented Feb 20, 2020

@arhag I feel this issue is better documented in eosio.cdt repo. BTW I could no longer find this member function (get). Did it get rename?

@lparisc
Copy link
Contributor

lparisc commented Feb 20, 2020

@arhag this is an old issue when eosiolib (now on eosio.cdt) used to be on eos. If still applicable, please move issue to eosio.cdt, then close here regardless.

@lparisc
Copy link
Contributor

lparisc commented Feb 20, 2020

@lparisc lparisc transferred this issue from EOSIO/eos Feb 20, 2020
@lparisc lparisc assigned iamveritas and unassigned lparisc Feb 20, 2020
@iamveritas iamveritas added the documentation Documentation related edits, non-breaking only label Feb 21, 2020
@iamveritas
Copy link
Contributor

iamveritas pushed a commit that referenced this issue Jan 5, 2021
add warning for iterator_to as well
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation related edits, non-breaking only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants