-
Notifications
You must be signed in to change notification settings - Fork 8k
[WIP] Easy User-land CSPRNG #1119
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
Changes from 1 commit
f8d7aec
26e4ed2
3c5fcac
e96b077
aa0ca69
b32e0d0
2c659ed
a1e6229
bbc9198
7a99db6
3d413ad
513d5c9
77f99cc
7ef5754
766ce0c
99e36d6
c6fc391
ab02b7b
fd0570b
7ae4917
a67e42f
f8a6d38
2990341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ PHP_FUNCTION(random_bytes) | |
| } | ||
| /* }}} */ | ||
|
|
||
| /* {{{ proto int random_int(int max) | ||
| /* {{{ proto int random_int(int min, int max) | ||
| Return an arbitrary pseudo-random integer */ | ||
| PHP_FUNCTION(random_int) | ||
| { | ||
|
|
@@ -115,12 +115,17 @@ PHP_FUNCTION(random_int) | |
| zend_ulong umax; | ||
| zend_ulong result; | ||
|
|
||
| if (ZEND_NUM_ARGS() == 1) { | ||
| php_error_docref(NULL, E_WARNING, "A minimum and maximum value are expected, only minimum given"); | ||
| RETURN_FALSE; | ||
| } | ||
|
|
||
| if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ll", &min, &max) == FAILURE) { | ||
| return; | ||
| } | ||
|
|
||
| if (min >= max) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if |
||
| php_error_docref(NULL, E_WARNING, "Minimum value must be greater than the maximum value"); | ||
| php_error_docref(NULL, E_WARNING, "Minimum value must be less than the maximum value"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe something like: 1st arg must be less than 2nd arg is more obvious for user? |
||
| RETURN_FALSE; | ||
| } | ||
|
|
||
|
|
||
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.
since you already have LONG_MIN and LONG_MAX, so if only minimum value min is given. then simply assume it means min to LONG_MAX?
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.
@laruence: I thought about the same thing but then I realize that reading:
random_int(10);might be understood as
10being the max.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.
hmm, that could be a doc issue.. but it's not a big deal :)
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.
Oops - this is a dingleberry left over from when
minandmaxwere optional args. They are both required in the current spec that's being voted on. I'll remove this check. :)