code format

This commit is contained in:
Dominik Maier
2020-03-28 12:59:41 +01:00
parent 4c11ef5d20
commit 1938a12222
4 changed files with 20 additions and 14 deletions

View File

@ -277,12 +277,13 @@ static void surgical_havoc_mutate(u8 *out_buf, s32 begin, s32 end) {
} }
/* This function calculates the next power of 2 greater or equal its argument. /* This function calculates the next power of 2 greater or equal its argument.
@return The rounded up power of 2 (if no overflow) or 0 on overflow. @return The rounded up power of 2 (if no overflow) or 0 on overflow.
*/ */
static inline size_t next_pow2(size_t in) { static inline size_t next_pow2(size_t in) {
if (in == 0 || in > (size_t)-1) return 0; /* avoid undefined behaviour under-/overflow */
if (in == 0 || in > (size_t)-1)
return 0; /* avoid undefined behaviour under-/overflow */
size_t out = in - 1; size_t out = in - 1;
out |= out >> 1; out |= out >> 1;
out |= out >> 2; out |= out >> 2;
@ -290,6 +291,7 @@ static inline size_t next_pow2(size_t in) {
out |= out >> 8; out |= out >> 8;
out |= out >> 16; out |= out >> 16;
return out + 1; return out + 1;
} }
/* This function makes sure *size is > size_needed after call. /* This function makes sure *size is > size_needed after call.
@ -299,8 +301,7 @@ static inline size_t next_pow2(size_t in) {
Will return NULL and free *buf if size_needed is <1 or realloc failed. Will return NULL and free *buf if size_needed is <1 or realloc failed.
@return For convenience, this function returns *buf. @return For convenience, this function returns *buf.
*/ */
static inline void *maybe_grow(void **buf, size_t *size, static inline void *maybe_grow(void **buf, size_t *size, size_t size_needed) {
size_t size_needed) {
/* No need to realloc */ /* No need to realloc */
if (likely(size_needed && *size >= size_needed)) return *buf; if (likely(size_needed && *size >= size_needed)) return *buf;
@ -312,9 +313,7 @@ static inline void *maybe_grow(void **buf, size_t *size,
size_t next_size = next_pow2(size_needed); size_t next_size = next_pow2(size_needed);
/* handle overflow */ /* handle overflow */
if (!next_size) { if (!next_size) { next_size = size_needed; }
next_size = size_needed;
}
/* alloc */ /* alloc */
*buf = realloc(*buf, next_size); *buf = realloc(*buf, next_size);

View File

@ -193,7 +193,8 @@ size_t afl_custom_pre_save(my_mutator_t *data, uint8_t *buf, size_t buf_size,
* @return The amount of possible iteration steps to trim the input. * @return The amount of possible iteration steps to trim the input.
* negative on error. * negative on error.
*/ */
int32_t afl_custom_init_trim(my_mutator_t *data, uint8_t *buf, size_t buf_size) { int32_t afl_custom_init_trim(my_mutator_t *data, uint8_t *buf,
size_t buf_size) {
// We simply trim once // We simply trim once
data->trimmming_steps = 1; data->trimmming_steps = 1;
@ -201,9 +202,12 @@ int32_t afl_custom_init_trim(my_mutator_t *data, uint8_t *buf, size_t buf_size)
data->cur_step = 0; data->cur_step = 0;
if (!maybe_grow(BUF_PARAMS(data, trim), buf_size)) { if (!maybe_grow(BUF_PARAMS(data, trim), buf_size)) {
perror("init_trim grow"); perror("init_trim grow");
return -1; return -1;
} }
memcpy(data->trim_buf, buf, buf_size); memcpy(data->trim_buf, buf, buf_size);
data->trim_size_current = buf_size; data->trim_size_current = buf_size;

View File

@ -771,7 +771,9 @@ static inline void TRK_ck_free(void *ptr, const char *file, const char *func,
@return The rounded up power of 2 (if no overflow) or 0 on overflow. @return The rounded up power of 2 (if no overflow) or 0 on overflow.
*/ */
static inline size_t next_pow2(size_t in) { static inline size_t next_pow2(size_t in) {
if (in == 0 || in > (size_t)-1) return 0; /* avoid undefined behaviour under-/overflow */
if (in == 0 || in > (size_t)-1)
return 0; /* avoid undefined behaviour under-/overflow */
size_t out = in - 1; size_t out = in - 1;
out |= out >> 1; out |= out >> 1;
out |= out >> 2; out |= out >> 2;
@ -779,6 +781,7 @@ static inline size_t next_pow2(size_t in) {
out |= out >> 8; out |= out >> 8;
out |= out >> 16; out |= out >> 16;
return out + 1; return out + 1;
} }
/* This function makes sure *size is > size_needed after call. /* This function makes sure *size is > size_needed after call.
@ -804,9 +807,7 @@ static inline void *ck_maybe_grow(void **buf, size_t *size,
size_t next_size = next_pow2(size_needed); size_t next_size = next_pow2(size_needed);
/* handle overflow */ /* handle overflow */
if (!next_size) { if (!next_size) { next_size = size_needed; }
next_size = size_needed;
}
/* alloc */ /* alloc */
*buf = ck_realloc(*buf, next_size); *buf = ck_realloc(*buf, next_size);

View File

@ -213,7 +213,8 @@ u8 trim_case_custom(afl_state_t *afl, struct queue_entry *q, u8 *in_buf) {
afl->stage_cur = 0; afl->stage_cur = 0;
afl->stage_max = afl->stage_max =
afl->mutator->afl_custom_init_trim(afl->mutator->data, in_buf, q->len); afl->mutator->afl_custom_init_trim(afl->mutator->data, in_buf, q->len);
if (unlikely(afl->stage_max) < 0) FATAL("custom_init_trim error ret: %d", afl->stage_max); if (unlikely(afl->stage_max) < 0)
FATAL("custom_init_trim error ret: %d", afl->stage_max);
if (afl->not_on_tty && afl->debug) if (afl->not_on_tty && afl->debug)
SAYF("[Custom Trimming] START: Max %d iterations, %u bytes", afl->stage_max, SAYF("[Custom Trimming] START: Max %d iterations, %u bytes", afl->stage_max,
q->len); q->len);
@ -273,7 +274,8 @@ u8 trim_case_custom(afl_state_t *afl, struct queue_entry *q, u8 *in_buf) {
/* Tell the custom mutator that the trimming was unsuccessful */ /* Tell the custom mutator that the trimming was unsuccessful */
afl->stage_cur = afl->stage_cur =
afl->mutator->afl_custom_post_trim(afl->mutator->data, 0); afl->mutator->afl_custom_post_trim(afl->mutator->data, 0);
if (unlikely(afl->stage_cur < 0)) FATAL("Error ret in custom_post_trim: %d", afl->stage_cur); if (unlikely(afl->stage_cur < 0))
FATAL("Error ret in custom_post_trim: %d", afl->stage_cur);
if (afl->not_on_tty && afl->debug) if (afl->not_on_tty && afl->debug)
SAYF("[Custom Trimming] FAILURE: %d/%d iterations", afl->stage_cur, SAYF("[Custom Trimming] FAILURE: %d/%d iterations", afl->stage_cur,
afl->stage_max); afl->stage_max);