Sun, 21 May 2023 11:52:06 +0200
fix dav-sync crash
dav/sync.c | file | annotate | diff | comparison | revisions |
--- a/dav/sync.c Sun May 07 11:53:10 2023 +0200 +++ b/dav/sync.c Sun May 21 11:52:06 2023 +0200 @@ -113,6 +113,69 @@ } } + + + +static bool nulliter_valid(void const *d) { + return false; +} + +static void * nulliter_current(void const *d) { + return NULL; +} + +void * nulliter_current_impl(void const *d) { + return NULL; +} + +void nulliter_next(void *d) { + // noop +} + +bool nulliter_flag_removal(void *d) { + return false; +} + + +static CxIterator nullIterator(void) { + CxIterator iter; + memset(&iter, 0, sizeof(CxIterator)); + iter.base.valid = nulliter_valid; + iter.base.current = nulliter_current; + iter.base.current_impl = nulliter_current_impl; + iter.base.next = nulliter_next; + iter.base.flag_removal = nulliter_flag_removal; + return iter; +} + +static CxIterator mapIteratorValues(CxMap *map) { + return map ? cxMapIteratorValues(map) : nullIterator(); +} + +static CxIterator listIterator(CxList *list) { + return list ? cxListIterator(list) : nullIterator(); +} + +typedef void*(*clonefunc)(void *elm, void *userdata); + +static CxMap* mapClone(const CxAllocator *a, CxMap *map, clonefunc clone, void *userdata) { + CxMap *newmap = cxHashMapCreate(a, map->store_pointer ? CX_STORE_POINTERS : map->item_size, map->size + 4); + + CxIterator i = cxMapIterator(map); + if(clone) { + cx_foreach(CxMapEntry*, entry, i) { + void *newdata = clone(entry->value, userdata); + cxMapPut(newmap, *entry->key, newdata); + } + } else { + cx_foreach(CxMapEntry*, entry, i) { + cxMapPut(newmap, *entry->key, entry->value); + } + } + + return newmap; +} + int dav_sync_main(int argc, char **argv); #ifdef _WIN32 @@ -674,7 +737,7 @@ CxMap *lres_removed = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); // type: LocalResource* //UcxMap *svrres = ucx_map_new(db->resources->count); - CxMap *dbres = NULL; // TODO: ucx_map_clone(db->resources, NULL, NULL); + CxMap *dbres = mapClone(cxDefaultAllocator, db->resources, NULL, NULL); CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); cxListInsert(stack, 0, ls->children); @@ -764,7 +827,7 @@ // find deleted resources // svrres currently contains all resources from the server // and will replace the current db->resources map later - CxIterator i = cxMapIteratorValues(dbres); + CxIterator i = mapIteratorValues(dbres); cx_foreach(LocalResource *, local, i) { if (res_matches_dir_filter(dir, local->path)) { continue;