Get address sanitizer mostly working

This commit is contained in:
Justine Tunney 2020-09-03 05:44:37 -07:00
parent 1f1f3cd477
commit 7327c345f9
149 changed files with 3777 additions and 3457 deletions

View file

@ -3,7 +3,6 @@
#include "libc/calls/internal.h"
#include "libc/calls/struct/sysinfo.h"
#include "libc/conv/conv.h"
#include "libc/conv/sizemultiply.h"
#include "libc/dce.h"
#include "libc/limits.h"
#include "libc/macros.h"
@ -861,6 +860,22 @@ void dlfree(void *mem) {
#endif /* FOOTERS */
}
/**
* Multiplies sizes w/ saturation and overflow detection.
*
* @param count may be 0 to for realloc() free() behavior
* @param opt_out set to count*itemsize or SIZE_MAX on overflow
* @return true on success or false on overflow
*/
static bool sizemultiply(size_t *opt_out, size_t count, size_t itemsize) {
size_t result;
bool overflowed;
overflowed = __builtin_mul_overflow(count, itemsize, &result);
if (overflowed) result = SIZE_MAX;
if (opt_out) *opt_out = result;
return !overflowed;
}
void *dlcalloc(size_t n_elements, size_t elem_size) {
void *mem;
size_t req;