Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UBSAN error in idhash.c #1638

Merged
merged 1 commit into from
Feb 5, 2023
Merged

Fix UBSAN error in idhash.c #1638

merged 1 commit into from
Feb 5, 2023

Conversation

shikokuchuo
Copy link
Contributor

Fix for UBSAN error, such as excerpt below:

idhash.c:132:14: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:44:28: note: nonnull attribute specified here

As id_reg_map is initialised as NULL and passing NULL to memcpy() is undefined. Should make no difference to compiled code. Purely to appease the automated checks I have to deal with on my side. Thanks!

Fix for UBSAN error. As `id_reg_map` is initialised as NULL and passing NULL to `memcpy()` is undefined. Should make no difference to compiled code. Purely to appease the automated checks I have to deal with on my side. Thanks!
@gdamore
Copy link
Contributor

gdamore commented Feb 5, 2023

Yeah, this is one of those stupid things -- when we start out we have a NULL value and zero length, so passing any value there should be meaningless because we aren't going to copy anything at all (the length is zero).

This is not on a hot code path, so this fix is fine. If it were on a hot code path we might elect instead to initialize the pointer to something (other than NULL), so that we don't need an extra branch instruction (and the possible stall.) This is probably more readable though, so thanks.

@gdamore gdamore merged commit e7a3e41 into nanomsg:master Feb 5, 2023
@shikokuchuo shikokuchuo deleted the patch-1 branch November 18, 2023 10:46
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.

None yet

2 participants