Skip to content

Commit

Permalink
Corpus generator: fix random char value of UTF-8.
Browse files Browse the repository at this point in the history
fixes github issue #184
  • Loading branch information
fatchanghao authored and markos committed Aug 29, 2022
1 parent 4d4940d commit a9ca0e4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions util/ng_corpus_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,14 @@ void CorpusGeneratorUtf8::generateCorpus(vector<string> &data) {
* that we've been asked for. */
unichar CorpusGeneratorUtf8::getRandomChar() {
u32 range = MAX_UNICODE + 1
- (UNICODE_SURROGATE_MAX + UNICODE_SURROGATE_MIN + 1);
- (UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1);
range = min(cProps.alphabetSize, range);
assert(range);

unichar c = 'a' + cProps.rand(0, range - 1);

if (c >= UNICODE_SURROGATE_MIN) {
c =+ UNICODE_SURROGATE_MAX + 1;
c += UNICODE_SURROGATE_MAX - UNICODE_SURROGATE_MIN + 1;
}

return c % (MAX_UNICODE + 1);
Expand Down

0 comments on commit a9ca0e4

Please sign in to comment.