Skip to content

Commit

Permalink
Clarify documentation for psnip_safe_*() functions
Browse files Browse the repository at this point in the history
Emphasize details of relation between psnip_safe_*() functions and
__builtin_*_overflow() builtins.
  • Loading branch information
szakharchenko committed Sep 9, 2019
1 parent fd46093 commit 26496ac
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion safe-math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ same. For each type and operation, we define:
psnip_safe_bool psnip_safe_{type_identifier}_{operation} ({T}* result, {T} a, {T} b);
```
which returns true if the operation succeeded, or false if it resulted
in an overflow (which is the opposite of how e.g.
`__builtin_*_overflow` builtins work).
For example, for addition on signed integers, there is
```c
Expand Down Expand Up @@ -86,7 +90,7 @@ things to watch out for if you choose this:
but GCC made a different choice.

In other words, `__builtin_*_overflow(a, b, res)` are macros
defined to `psnip_safe_*(res, a, b)` so existing code needn't
defined to `(!psnip_safe_*(res, a, b))` so existing code needn't
be altered.

## The `safe_larger_*` API
Expand Down

0 comments on commit 26496ac

Please sign in to comment.