diff options
author | Anthony Wang | 2023-07-19 09:42:08 -0500 |
---|---|---|
committer | Anthony Wang | 2023-07-19 09:42:08 -0500 |
commit | 1f36fa09fa178cd8e7d6ba3ce346abe6faa838b1 (patch) | |
tree | 8c78e14265f2e7ce7bce7f0cab6ab68c5b075f1a | |
parent | 012a500fdb7aab0b00e2bf80855485a0800abf94 (diff) |
Make sure the sum of weights is positive to avoid undefined behavior
-rw-r--r-- | sd.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -59,6 +59,9 @@ int main(int argc, char* argv[]) { assert(system("stty -F /dev/tty -echo") == 0); while (true) { + /* Make sure sum of weights is positive */ + assert(seg[1] > 0); + int x = (long long)rand() * rand() % seg[1]; int res[2]; query(res, x, 0, N-1, 1); |