Check for integer overflows when allocating memory #3549
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404
Add a couple of functions to
Utils
taking advantage of the compiler builtinfunctions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.
Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only
size_t
for the multiplicationoperands.
Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the
__muloti4
intrinsic function which is usually defined inlibgcc
,libcompiler_rt
orlibcompiler_rt-extras
libraries. In the NDK case the64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.