It is perfectly fine for the high nibble of the low 32 bits of a pointer to be 6. Use NULL as a marker for missing entries. Signed-off-by: Hristo Venev <hristo@xxxxxxxxxx> --- cachefilesd.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/cachefilesd.c b/cachefilesd.c index d4d236f..851815d 100644 --- a/cachefilesd.c +++ b/cachefilesd.c @@ -30,6 +30,7 @@ #define CACHEFILESD_VERSION "0.10.10" #define _GNU_SOURCE +#include <assert.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> @@ -1092,7 +1093,6 @@ static void put_object(struct object *object) parent = object->parent; - memset(object, 0x6d, sizeof(struct object)); free(object); if (parent) @@ -1213,7 +1213,7 @@ static void insert_into_cull_table(struct object *object) /* newest object in table will be displaced by this one */ put_object(cullbuild[0]); - cullbuild[0] = (void *)(0x6b000000 | __LINE__); + cullbuild[0] = NULL; object->usage++; /* place directly in first slot if second is older */ @@ -1391,7 +1391,7 @@ next: if (loop == nr_in_ready_table - 1) { /* child was oldest object */ - cullready[--nr_in_ready_table] = (void *)(0x6b000000 | __LINE__); + cullready[--nr_in_ready_table] = NULL; put_object(child); goto removed; } @@ -1400,7 +1400,7 @@ next: memmove(&cullready[loop], &cullready[loop + 1], (nr_in_ready_table - (loop + 1)) * sizeof(cullready[0])); - cullready[--nr_in_ready_table] = (void *)(0x6b000000 | __LINE__); + cullready[--nr_in_ready_table] = NULL; put_object(child); goto removed; } @@ -1409,17 +1409,11 @@ next: if (cullbuild[loop] == child) break; - if (loop == nr_in_build_table - 1) { - /* child was oldest object */ - cullbuild[--nr_in_build_table] = (void *)(0x6b000000 | __LINE__); - put_object(child); - } - else if (loop < nr_in_build_table - 1) { - /* child was somewhere in between */ + if (loop < nr_in_build_table) { memmove(&cullbuild[loop], &cullbuild[loop + 1], (nr_in_build_table - (loop + 1)) * sizeof(cullbuild[0])); - cullbuild[--nr_in_build_table] = (void *)(0x6b000000 | __LINE__); + cullbuild[--nr_in_build_table] = NULL; put_object(child); } @@ -1531,7 +1525,7 @@ static void decant_cull_table(void) n = copy * sizeof(cullready[0]); memcpy(cullready, cullbuild, n); - memset(cullbuild, 0x6e, n); + memset(cullbuild, 0, n); nr_in_ready_table = nr_in_build_table; nr_in_build_table = 0; goto check; @@ -1558,8 +1552,9 @@ static void decant_cull_table(void) memmove(&cullready[copy], &cullready[0], nr_in_ready_table * sizeof(cullready[0])); nr_in_ready_table += copy; - memcpy(&cullready[0], &cullbuild[leave], copy * sizeof(cullready[0])); - memset(&cullbuild[leave], 0x6b, copy * sizeof(cullbuild[0])); + n = copy * sizeof(cullready[0]); + memcpy(&cullready[0], &cullbuild[leave], n); + memset(&cullbuild[leave], 0, n); nr_in_build_table = leave; if (copy + leave > culltable_size) @@ -1567,8 +1562,7 @@ static void decant_cull_table(void) check: for (loop = 0; loop < nr_in_ready_table; loop++) - if (((long)cullready[loop] & 0xf0000000) == 0x60000000) - abort(); + assert(cullready[loop]); } /*****************************************************************************/ @@ -1645,6 +1639,6 @@ static void cull_objects(void) if (cullready[nr_in_ready_table - 1]->cullable) { cull_object(cullready[nr_in_ready_table - 1]); - cullready[--nr_in_ready_table] = (void *)(0x6b000000 | __LINE__); + cullready[--nr_in_ready_table] = NULL; } } -- 2.43.0