Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mulDiv() return from pair<bool, std::uint64_t> to optional<std::uint64_t> #3495

Closed
carlhua opened this issue Jul 8, 2020 · 1 comment · Fixed by #4243
Closed

Change mulDiv() return from pair<bool, std::uint64_t> to optional<std::uint64_t> #3495

carlhua opened this issue Jul 8, 2020 · 1 comment · Fixed by #4243
Assignees
Labels
RIPD Export Exported from legacy JIRA issue tracking Tech Debt Non-urgent improvements

Comments

@carlhua
Copy link
Contributor

carlhua commented Jul 8, 2020

The current mulDiv interface is error prone, and it’s easy to ignore when overflow occurs. The suggestion is that we change this interface to use optional in place of pair<boool, value>.

This suggestion should decrease the likelihood of people ignoring overflow. It’s also very convenient to use optional::value_or() as a way to explicitly recover from overflow.

Exported from RIPD-1791

@carlhua carlhua added Tech Debt Non-urgent improvements RIPD Export Exported from legacy JIRA issue tracking labels Jul 8, 2020
ckeshava pushed a commit to ckeshava/rippled that referenced this issue Jul 19, 2022
ckeshava pushed a commit to ckeshava/rippled that referenced this issue Jul 21, 2022
@intelliot
Copy link
Collaborator

May be fixed by #4243

@intelliot intelliot linked a pull request Mar 14, 2023 that will close this issue
HowardHinnant pushed a commit to HowardHinnant/rippled that referenced this issue May 22, 2023
ckeshava pushed a commit to ckeshava/rippled that referenced this issue Jun 5, 2023
This commit will include limits header file for satisfying gcc's numeric_limits incomplete_type requirement. Interestingly, the build system on MacOS does not throw an error despite the lack of #include <limits.h> preprocessing directive.

Certain unused imports are removed from mulDiv implementation file
ckeshava pushed a commit to ckeshava/rippled that referenced this issue Jul 5, 2023
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
  - This is an error-prone interface as it is easy to ignore when
    overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
  of ignoring overflow.
  - It also allows for the use of optional::value_or() as a way to
    explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
  satisfy gcc's numeric_limits incomplete_type requirement.

Fix XRPLF#3495

---------

Co-authored-by: John Freeman <[email protected]>
intelliot pushed a commit that referenced this issue Jul 6, 2023
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
  - This is an error-prone interface as it is easy to ignore when
    overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
  of ignoring overflow.
  - It also allows for the use of optional::value_or() as a way to
    explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
  satisfy gcc's numeric_limits incomplete_type requirement.

Fix #3495

---------

Co-authored-by: John Freeman <[email protected]>
ckeshava added a commit to ckeshava/rippled that referenced this issue Jul 10, 2023
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
  - This is an error-prone interface as it is easy to ignore when
    overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
  of ignoring overflow.
  - It also allows for the use of optional::value_or() as a way to
    explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
  satisfy gcc's numeric_limits incomplete_type requirement.

Fix XRPLF#3495

---------

Co-authored-by: John Freeman <[email protected]>
ckeshava added a commit to ckeshava/rippled that referenced this issue Sep 22, 2023
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
  - This is an error-prone interface as it is easy to ignore when
    overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
  of ignoring overflow.
  - It also allows for the use of optional::value_or() as a way to
    explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
  satisfy gcc's numeric_limits incomplete_type requirement.

Fix XRPLF#3495

---------

Co-authored-by: John Freeman <[email protected]>
ckeshava added a commit to ckeshava/rippled that referenced this issue Sep 25, 2023
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type.
  - This is an error-prone interface as it is easy to ignore when
    overflow occurs.
- Using a return type of `std::optional` should decrease the likelihood
  of ignoring overflow.
  - It also allows for the use of optional::value_or() as a way to
    explicitly recover from overflow.
- Include limits.h header file preprocessing directive in order to
  satisfy gcc's numeric_limits incomplete_type requirement.

Fix XRPLF#3495

---------

Co-authored-by: John Freeman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RIPD Export Exported from legacy JIRA issue tracking Tech Debt Non-urgent improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants