Skip to content

Conversation

@joshStillerman
Copy link
Contributor

Replace pointer-int casts with memcpy

Fixes #2982
** Note there are strict aliasing violations in other parts of the codebase too.**

treeshrp.h - add int_to_nid function
- add nid_to_int function
- fix RFA macros to be aliasing safe

TreeAddNode.c - remove unnessary cast
TreeDeleteNode.c - use nid_to_int function
TreeGetNci.c - use int_to_nid and nid_to_int functions
- fix other strict-aliasing violations
TreeGetRecord.c - use int_to_nid function
TreeOpen.c - remove volatile qualifier
- use nid_to_int function
TreeRenameNode.c - use nid_to_int functions

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors pointer casting operations by replacing unsafe pointer casts with safer alternatives. The changes introduce helper functions for type conversions and improve code maintainability by avoiding undefined behavior from type-punning through pointer casts.

Key changes:

  • Replaced macro-based RFA conversion with inline functions that perform byte-by-byte manipulation
  • Added helper functions nid_to_int() and int_to_nid() for safe NID/int conversions
  • Updated all call sites to use the new helper functions and memcpy instead of pointer casts

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
treeshr/treeshrp.h Introduces inline functions for RFA-to-seek conversions and NID/int type conversions, replacing unsafe pointer cast macros
treeshr/TreeRenameNode.c Updates to use nid_to_int() helper instead of pointer casting
treeshr/TreeOpen.c Updates to use nid_to_int() helper; removes volatile qualifier from brother_nid
treeshr/TreeGetRecord.c Updates to use int_to_nid() helper instead of pointer casting
treeshr/TreeGetNci.c Replaces pointer casts with memcpy and helper functions for safer type conversions
treeshr/TreeDeleteNode.c Updates to use nid_to_int() helper instead of pointer casting
treeshr/TreeAddNode.c Simplifies code by removing unnecessary pointer cast (variable is already an int)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mwinkel-dev
Copy link
Contributor

These changes look OK to me. (It will be good when we have all the other "strict aliasing violations" fixed too.)

static void SubtreeNodeConnect(PINO_DATABASE *dblist, NODE *parent,
NODE *subtreetop)
{
NID child_nid, parent_nid = {0, 0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're making changes here, should we move each of these on their own line?

@mwinkel-dev
Copy link
Contributor

This PR is presently the result of a "merge" and not a "rebase". The most recent commit has two parents.

2 parents 2beaf07 + c461e1 commit 6e8fb5d

Replace  pointer-int casts with memcpy

Fixes #2982
** Note there are strict aliasing violations in other parts of the codebase too.**

treeshrp.h - add int_to_nid function
            - add nid_to_int function
            - fix RFA macros to be aliasing safe

TreeAddNode.c - remove unnessary cast
TreeDeleteNode.c - use nid_to_int function
TreeGetNci.c - use int_to_nid and nid_to_int functions
            - fix other strict-aliasing violations
TreeGetRecord.c - use int_to_nid function
TreeOpen.c - remove volatile qualifier
            - use nid_to_int function
TreeRenameNode.c - use nid_to_int functions
remove bogus RFA macros in treeshrp.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird behavior of TCL directory command

5 participants