code format

This commit is contained in:
Dominik Maier
2020-10-06 15:38:36 +02:00
parent a4b60ca5b6
commit 74dc227c44
5 changed files with 48 additions and 18 deletions

View File

@ -770,24 +770,33 @@ u32 calculate_score(afl_state_t *afl, struct queue_entry *q) {
/* Tell afl that this testcase may be evicted from the cache */
inline void queue_testcase_release(afl_state_t *afl, struct queue_entry *q) {
(void) afl;
(void)afl;
q->testcase_refs--;
if (unlikely(q->testcase_refs < 0)) { FATAL("Testcase refcount smaller than 0"); }
if (unlikely(q->testcase_refs < 0)) {
FATAL("Testcase refcount smaller than 0");
}
}
/* Returns the testcase buf from the file behind this queue entry.
Increases the refcount. */
u8 *queue_testcase_take(afl_state_t *afl, struct queue_entry *q) {
if (!q->testcase_buf) {
u32 tid = 0;
/* Buf not cached, let's do that now */
if (likely(afl->q_testcase_cache_count == TESTCASE_CACHE_SIZE)) {
/* Cache full. We neet to evict one to map one.
Get a random one which is not in use */
do {
tid = rand_below(afl, afl->q_testcase_cache_count);
tid = rand_below(afl, afl->q_testcase_cache_count);
} while (afl->q_testcase_cache[tid]->testcase_refs > 0);
@ -795,21 +804,19 @@ u8 *queue_testcase_take(afl_state_t *afl, struct queue_entry *q) {
/* free the current buf from cache */
munmap(old_cached->testcase_buf, old_cached->len);
old_cached->testcase_buf = NULL;
} else {
tid = afl->q_testcase_cache_count;
afl->q_testcase_cache_count++;
}
/* Map the test case into memory. */
int fd = open(q->fname, O_RDONLY);
if (unlikely(fd < 0)) {
PFATAL("Unable to open '%s'", q->fname);
}
if (unlikely(fd < 0)) { PFATAL("Unable to open '%s'", q->fname); }
u32 len = q->len;
@ -827,8 +834,15 @@ u8 *queue_testcase_take(afl_state_t *afl, struct queue_entry *q) {
afl->q_testcase_cache[tid] = q;
}
q->testcase_refs++;
if (!q->testcase_buf) { FATAL("Testcase buf is NULL, this should never happen"); }
if (!q->testcase_buf) {
FATAL("Testcase buf is NULL, this should never happen");
}
return q->testcase_buf;
}