-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: avoid repeating same result in __randname on passing same template pointer #18914
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
Conversation
|
|
||
| __clock_gettime(CLOCK_REALTIME, &ts); | ||
| r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template; | ||
| r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template + seed++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mark with /* XXX EMSCRIPTEN ... */ and maybe try to keep the changes isolated from the original code. How about:
/* XXX EMSCRIPTEN: avoid repeating the same result when __clock_gettime does not change between calls. */
static unsigned int seed = 0;
r += seed++;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood, updating it
sbc100
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % comment
sbc100
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give a better title to this PR. Perhaps "Avoid repeating the same result in __randname"?
|
update the code and title, does it look ok? |
|
|
||
| /* XXX EMSCRIPTEN: avoid repeating the same result when __clock_gettime does not change between calls. */ | ||
| static unsigned int seed = 0; | ||
| r += seed++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is seed the right name for this? How about increment or counter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, counter looks good
Attempted to fix the issue of the same pointer possibly causing the same random path to be returned by adding a static variable to keep count, I am unsure how I could add a test for this 😅
Fixes: #18591