From 1cc471d69fc6ff5dc835462b712645415f8feca4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Aug 2010 11:00:41 +1000 Subject: s4-ldb: add some comments explaining the ltdb_index_idxptr() function this function copes with alignment sensitive CPUs Signed-off-by: Andrew Bartlett --- source4/lib/ldb/ldb_tdb/ldb_index.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 828dca1f2c..4f5979877b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -95,6 +95,11 @@ static int ltdb_dn_list_find_str(struct dn_list *list, const char *dn) return ltdb_dn_list_find_val(list, &v); } +/* + this is effectively a cast function, but with lots of paranoia + checks and also copes with CPUs that are fussy about pointer + alignment + */ static struct dn_list *ltdb_index_idxptr(struct ldb_module *module, TDB_DATA rec, bool check_parent) { struct dn_list *list; @@ -103,6 +108,9 @@ static struct dn_list *ltdb_index_idxptr(struct ldb_module *module, TDB_DATA rec "Bad data size for idxptr %u", (unsigned)rec.dsize); return NULL; } + /* note that we can't just use a cast here, as rec.dptr may + not be aligned sufficiently for a pointer. A cast would cause + platforms like some ARM CPUs to crash */ memcpy(&list, rec.dptr, sizeof(void *)); list = talloc_get_type(list, struct dn_list); if (list == NULL) { -- cgit