Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions link-grammar/utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ size_t lg_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
* Emulate rand_r() using rand_s() in a way that is enough for our needs.
* Windows doesn't have rand_r(), and its rand_s() is different: It
* returns an error indication and not the random number like rand_r().
* The value it returns is through its argument.
* The value it returns is through its argument. Failure is fatal and
* triggers an assert.
*
* Note that "#define _CRT_RAND_S" is needed before "#include <stdlib.h>".
*/
int rand_r(unsigned int *s)
{
rand_s(s);
if (*s > INT_MAX) *s -= INT_MAX;
assert(0 == rand_s(s), "rand_s() failed");
if (*s > INT_MAX) *s -= INT_MAX;

return *s;
}
Expand Down
Loading