-
Notifications
You must be signed in to change notification settings - Fork 449
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
Move random_int() to util.cpp #5555
base: master
Are you sure you want to change the base?
Conversation
@computezrmle, please fix the failed build. |
As for Release-x64-msbuild As for Release-ARM64-msbuild |
This was an unrelated issue, now fixed by build rerun. |
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.
There are still two failing builds.
Please check them and fix.
Thank you in advance.
if (!hLib) { | ||
fprintf(stderr, "Error: can't load ADVAPI32.DLL\n"); | ||
} | ||
BOOLEAN (APIENTRY *pfn)(void*, ULONG) = |
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.
If the library was not loaded correctly two lines above - this will fail with an exception
lib/util.cpp
Outdated
} | ||
fclose(f); | ||
#endif | ||
return n; |
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.
What will be returned in case of an error?
We should indicate somehow that the function returns a proper result.
lib/util.cpp
Outdated
@@ -542,3 +542,38 @@ bool process_exists(int pid) { | |||
} | |||
|
|||
#endif | |||
|
|||
unsigned int random_int() { |
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.
I suggest to change signature function to something like this:
bool random_int(unsigned int& value)
And return the random value using the output parameter, and return true
on success and false
in case of an error
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.
Also, then you need to adjust crypt_prog.cpp
with the new function signature
Is there a need for this outside of crypt_prog? |
Can the recent build issues be solved without too much effort? 1st idea to get a random number was to use the standard library functions from C++11. Next idea was to use
As Other sources for seed appear to be less "natural". Can you confirm that If yes, this may be fine enough to cover concurrently starting processes: or, to avoid |
lib/util.cpp
Outdated
} | ||
FreeLibrary(hLib); | ||
#else | ||
FILE* f = fopen("/dev/random", "r"); |
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.
FILE* f = fopen("/dev/random", "r"); | |
FILE* f = boinc::fopen("/dev/random", "r"); |
lib/util.cpp
Outdated
if (!f) { | ||
return 2; | ||
} | ||
if (1 != fread(&n, sizeof(n), 1, f)) { |
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.
if (1 != fread(&n, sizeof(n), 1, f)) { | |
if (1 != boinc::fread(&n, sizeof(n), 1, f)) { |
lib/util.cpp
Outdated
if (1 != fread(&n, sizeof(n), 1, f)) { | ||
return 3; | ||
} | ||
fclose(f); |
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.
fclose(f); | |
boinc::fclose(f); |
lib/crypt_prog.cpp
Outdated
die("random_int"); | ||
} | ||
srand(srand_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.
run locally this command to remove trailing spaces:
python3 ci_tools/trailing_whitespaces_check.py . --fix
I think, having this as a generally available function won't hurt and could be helpful. |
In addition: Added 'return 0' at the end of 'random_int()' to mitigate a runtime error.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5555 +/- ##
============================================
- Coverage 10.80% 10.79% -0.01%
Complexity 1068 1068
============================================
Files 279 279
Lines 36294 36303 +9
Branches 8409 8412 +3
============================================
Hits 3920 3920
- Misses 31980 31989 +9
Partials 394 394
|
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.
Looks good to me.
@davidpanderson, if you are ok with this - feel free to merge it
Sorry, but I don't see a use case for this. |
random_int()
can easily be used as seed forsrand()
from various functions if it is inutil.cpp
.This is not possible if it is in
crypt_prog.cpp
sincecrypt_prog.cpp
is not included in the standard build process.Instead,
tools/makefile_sign_executable
must be used to build it.See:
https://boinc.berkeley.edu/trac/wiki/KeySetup#Filesigningutilities