diff options
author | osdl.net!shemminger <osdl.net!shemminger> | 2005-03-30 18:11:49 +0000 |
---|---|---|
committer | osdl.net!shemminger <osdl.net!shemminger> | 2005-03-30 18:11:49 +0000 |
commit | f8f9de56f2c75776cb103f35e6a788630add0a13 (patch) | |
tree | 3f7d6b964c37445995ed8cef7c183eb68bc7a974 /netem | |
parent | e39a637db00980e750bc2ed19f12f673d9e5c928 (diff) |
Switch to stack (rather than calloc) for tables.
(Logical change 1.176)
Diffstat (limited to 'netem')
-rw-r--r-- | netem/normal.c | 15 | ||||
-rw-r--r-- | netem/paretonormal.c | 14 |
2 files changed, 8 insertions, 21 deletions
diff --git a/netem/normal.c b/netem/normal.c index e6683db8..dbdebb1d 100644 --- a/netem/normal.c +++ b/netem/normal.c @@ -20,21 +20,16 @@ normal(double x, double mu, double sigma) return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); } + int main(int argc, char **argv) { - double x, *table; int i, n; - - table = calloc(sizeof(double), TABLESIZE+1); - if (!table) { - fprintf(stderr, "Not enough memory\n"); - return 1; - } - + double x; + double table[TABLESIZE+1]; for (x = -10.0; x < 10.05; x += .00005) { - i = (int)rint(TABLESIZE*normal(x, 0.0, 1.0)); + i = rint(TABLESIZE * normal(x, 0.0, 1.0)); table[i] = x; } @@ -51,6 +46,6 @@ main(int argc, char **argv) n = 0; } } - free(table); + return 0; } diff --git a/netem/paretonormal.c b/netem/paretonormal.c index c793df6d..528de78c 100644 --- a/netem/paretonormal.c +++ b/netem/paretonormal.c @@ -29,7 +29,6 @@ normal(double x, double mu, double sigma) return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); } - static const double a=3.0; static int @@ -50,18 +49,12 @@ paretovalue(int i) int main(int argc, char **argv) { - double x; - double *table; int i,n; - - table = calloc(TABLESIZE+1, sizeof(double)); - if (!table) { - fprintf(stderr, "Out of memory!\n"); - exit(1); - } + double x; + double table[TABLESIZE]; for (x = -10.0; x < 10.05; x += .00005) { - i = (int)rint(TABLESIZE*normal(x, 0.0, 1.0)); + i = rint(TABLESIZE*normal(x, 0.0, 1.0)); table[i] = x; } printf( @@ -84,7 +77,6 @@ main(int argc, char **argv) n = 0; } } - free(table); return 0; } |