diff --git a/treeshr/TreeAddNode.c b/treeshr/TreeAddNode.c index e1794c484e..68cf46346e 100644 --- a/treeshr/TreeAddNode.c +++ b/treeshr/TreeAddNode.c @@ -196,7 +196,7 @@ int _TreeAddNode(void *dbid, char const *name, int *nid_out, char usage) &scratch_nci, &ncilocked); if (STATUS_OK) { - if (_TreeIsOn(dblist, *(int *)&parent_nid) & 1) + if (_TreeIsOn(dblist, parent_nid) & 1) new_nci.flags &= (unsigned)~NciM_PARENT_STATE; else new_nci.flags |= NciM_PARENT_STATE; diff --git a/treeshr/TreeDeleteNode.c b/treeshr/TreeDeleteNode.c index 2266864153..03f3bb8c98 100644 --- a/treeshr/TreeDeleteNode.c +++ b/treeshr/TreeDeleteNode.c @@ -223,8 +223,8 @@ extern void _TreeDeleteNodeExecute(void *dbid) while (_TreeDeleteNodeGetNid(dbid, (int *)&nid) & 1) { int found = 0; - _TreeRemoveNodesTags(dbid, *(int *)&nid); - _TreeSetNoSubtree(dbid, *(int *)&nid); + _TreeRemoveNodesTags(dbid, nid_to_int(&nid)); + _TreeSetNoSubtree(dbid, nid_to_int(&nid)); node = nid_to_node(dblist, &nid); parent = parent_of(0, node); if (child_of(0, parent) == node) diff --git a/treeshr/TreeGetNci.c b/treeshr/TreeGetNci.c index 9bc890389e..0297c51955 100644 --- a/treeshr/TreeGetNci.c +++ b/treeshr/TreeGetNci.c @@ -91,7 +91,7 @@ extern void **TreeCtx(); static char *Treename(PINO_DATABASE *dblist, int nid_in) { TREE_INFO *info; - NID nid = *(NID *)&nid_in; + NID nid = int_to_nid(nid_in); unsigned int treenum; for (info = dblist->tree_info, treenum = 0; info && treenum < nid.tree; info = info->next_info) @@ -220,7 +220,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) void *dbid = *TreeCtx(); INIT_STATUS_AS TreeSUCCESS; PINO_DATABASE *dblist = (PINO_DATABASE *)dbid; - NID nid = *(NID *)&nid_in; + NID nid = int_to_nid(nid_in); int node_number; TREE_INFO *info; NCI_ITM *itm; @@ -449,7 +449,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) for (node = child_of(dblist, node); node; count++, node = brother_of(dblist, node) ? brother_of(dblist, node) : 0) ; - *(int *)(itm->pointer) = count; + memcpy(itm->pointer, &count, sizeof(count)); break; case NciNUMBER_OF_MEMBERS: break_on_no_node; @@ -459,7 +459,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) for (node = member_of(node); node; count++, node = brother_of(dblist, node) ? brother_of(dblist, node) : 0) ; - *(int *)(itm->pointer) = count; + memcpy(itm->pointer, &count, sizeof(count)); break; case NciNUMBER_OF_ELTS: break_on_no_node; @@ -468,7 +468,7 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) for (count = 0; swapint16(&cng_node->conglomerate_elt) > count; count++, cng_node++) ; - *(int *)(itm->pointer) = count; + memcpy(itm->pointer, &count, sizeof(count)); break; case NciCHILDREN_NIDS: { @@ -665,7 +665,10 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm) *(NID *)itm->pointer = out_nid; } else - *(int *)itm->pointer = 0; + { + int zero = 0; + memcpy(itm->pointer, &zero, sizeof(zero)); + } break; } case NciDTYPE_STR: @@ -766,7 +769,7 @@ static char *getPath(PINO_DATABASE *dblist, NODE *node, int remove_tree_refs) for (info = dblist->tree_info, i = 0; info && i < nid.tree; i++, info = info->next_info) ; - if ((tag = _TreeFindNodeTags((void *)dblist, *(int *)&nid, &ctx)) != NULL) + if ((tag = _TreeFindNodeTags((void *)dblist, nid_to_int(&nid), &ctx)) != NULL) { string[0] = '\\'; string[1] = '\0'; diff --git a/treeshr/TreeGetRecord.c b/treeshr/TreeGetRecord.c index a245eb28cd..4f442b92b2 100644 --- a/treeshr/TreeGetRecord.c +++ b/treeshr/TreeGetRecord.c @@ -257,7 +257,7 @@ typedef ARRAY(struct descriptor *) array_dsc; int TreeMakeNidsLocal(struct descriptor *dsc_ptr, int nid) { int status = 1; - unsigned char tree = ((NID *)&nid)->tree; + unsigned char tree = int_to_nid(nid).tree; if (dsc_ptr == NULL) status = 1; else diff --git a/treeshr/TreeOpen.c b/treeshr/TreeOpen.c index 07ae3bea5f..e063935d6d 100644 --- a/treeshr/TreeOpen.c +++ b/treeshr/TreeOpen.c @@ -1175,22 +1175,18 @@ static void SubtreeNodeConnect(PINO_DATABASE *dblist, NODE *parent, NODE *subtreetop) { NID child_nid, parent_nid = {0, 0}; - /* - * make brother_nid volatile so that the optimizer does not - * decide to optimize it out and replace it with a zero. - */ - volatile NID brother_nid = {0,0}; + NID brother_nid = {0,0}; NODE *brother = brother_of(dblist, parent); parent->usage = TreeUSAGE_SUBTREE_REF; subtreetop->usage = TreeUSAGE_SUBTREE_TOP; node_to_nid(dblist, subtreetop, &child_nid); node_to_nid(dblist, parent_of(dblist, parent), &parent_nid); - parent->child = *(int *)&child_nid; + parent->child = nid_to_int(&child_nid); if (brother) { node_to_nid(dblist, brother_of(dblist, parent), &brother_nid); } - subtreetop->brother = *(int *)&brother_nid; - subtreetop->parent = *(int *)&parent_nid; + subtreetop->brother = nid_to_int(&brother_nid); + subtreetop->parent = nid_to_int(&parent_nid); memcpy(subtreetop->name, parent->name, sizeof(subtreetop->name)); return; } diff --git a/treeshr/TreeRenameNode.c b/treeshr/TreeRenameNode.c index 8064cf2094..d79d0d0b6c 100644 --- a/treeshr/TreeRenameNode.c +++ b/treeshr/TreeRenameNode.c @@ -256,8 +256,8 @@ static int FixParentState(PINO_DATABASE *dblist, NODE *parent_ptr, in the flag longword and the parent state argument to SET_PARENT_STATE are negative boolean logic. ****************************************************/ - parent_state = _TreeIsOn(dblist, *(int *)&parent_nid) & 1; - status = _TreeGetNci(dblist, *(int *)&child_nid, child_itm_list); + parent_state = _TreeIsOn(dblist, nid_to_int(&parent_nid)) & 1; + status = _TreeGetNci(dblist, nid_to_int(&child_nid), child_itm_list); if (STATUS_OK) { child_parent_state = ((child_flags & NciM_PARENT_STATE) == 0); diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index 44e278ac23..b02f8091de 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -396,17 +396,6 @@ typedef struct unsigned char rfa[6]; } RFA; -#ifdef RFA_MACROS -#define RfaToSeek(rfa) \ - (((*(unsigned int *)rfa - 1) * 512) + \ - (*(unsigned short *)&((char *)rfa)[4] & 0x1ff)) -#define SeekToRfa(seek, rfa) \ - { \ - *(unsigned int *)rfa = (unsigned int)(seek / 512 + 1); \ - *(unsigned short *)&(((char *)rfa)[4]) = (unsigned short)(seek % 512); \ - } -#endif - /**************************************** RECORD_HEADER VFC portion of file. @@ -642,6 +631,20 @@ typedef struct pino_database void *dispatch_table; /* pointer to dispatch table generated by dispatch/build */ } PINO_DATABASE; +static inline int nid_to_int(NID *nid) +{ + int result; + memcpy(&result, nid, sizeof(int)); + return result; +} + +static inline NID int_to_nid(int nid_int) +{ + NID nid; + memcpy(&nid, &nid_int, sizeof(int)); + return nid; +} + static inline NODE *nid_to_node(PINO_DATABASE *dbid, NID *nid) { TREE_INFO *info; @@ -793,7 +796,7 @@ static inline int node_to_nid(PINO_DATABASE *dbid, NODE *node, NID *nid_out) nid.tree = 0; if (nid_out) *nid_out = nid; - return *(int *)&nid; + return nid_to_int(&nid); } /******************************************