projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fio: Fix (unsigned) integer overflow issues
[fio.git]
/
lib
/
zipf.c
diff --git
a/lib/zipf.c
b/lib/zipf.c
index 8b581fafff6e9e0dd8b1423d7e7d0b9e5e2d94de..681df70069ac27419b4545dcbac0ee2de81fdbee 100644
(file)
--- a/
lib/zipf.c
+++ b/
lib/zipf.c
@@
-69,10
+69,12
@@
unsigned long long zipf_next(struct zipf_state *zs)
else
val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
else
val = 1 + (unsigned long long)(n * pow(eta*rand_uni - eta + 1.0, alpha));
+ val--;
+
if (!zs->disable_hash)
if (!zs->disable_hash)
-
return (__hash_u64(val - 1) + zs->rand_off) % zs->nranges
;
+
val = __hash_u64(val)
;
- return (val
- 1
+ zs->rand_off) % zs->nranges;
+ return (val + zs->rand_off) % zs->nranges;
}
void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
}
void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
@@
-85,12
+87,14
@@
void pareto_init(struct zipf_state *zs, unsigned long nranges, double h,
unsigned long long pareto_next(struct zipf_state *zs)
{
double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
unsigned long long pareto_next(struct zipf_state *zs)
{
double rand = (double) __rand(&zs->rand) / (double) FRAND32_MAX;
- unsigned long long n = zs->nranges - 1;
+ unsigned long long n;
+
+ n = (zs->nranges - 1) * pow(rand, zs->pareto_pow);
if (!zs->disable_hash)
if (!zs->disable_hash)
-
return (__hash_u64(n * pow(rand, zs->pareto_pow)) + zs->rand_off) % zs->nranges
;
+
n = __hash_u64(n)
;
- return (
unsigned long long) (n * pow(rand, zs->pareto_pow) + zs->rand_off)
% zs->nranges;
+ return (
n + zs->rand_off)
% zs->nranges;
}
void zipf_disable_hash(struct zipf_state *zs)
}
void zipf_disable_hash(struct zipf_state *zs)