# HG changeset patch # User Markus Bröker # Date 1239879039 -7200 # Node ID 829976007e628524f0e9d9008ba2eff4b6597fb1 # Parent d0578510aea169a442ce98fccd49e14072b2a4f7 getrandom macro fixed the getrandom expanded to the wrong value when dealing with expressions. committer: Markus Bröker diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -62,6 +62,7 @@ TARGET += duff TARGET += unicode TARGET += fts +TARGET += clplaner .SUFFIXES: .c .cc .asm @@ -301,6 +302,10 @@ @echo Linking $< ... @$(CC) -o $@ $< +clplaner: clplaner.o + @echo Compiling $<... + @$(CC) -o $@ $< + .PHONY: beauty clean uninstall clean: diff --git a/crypt.c b/crypt.c --- a/crypt.c +++ b/crypt.c @@ -8,7 +8,7 @@ #include #include -#define GETRANDOM(max) ('a'+(int)((float)max*rand()/RAND_MAX+1.0)) +#define GETRANDOM(max) ('a'+(int)((float)(max)*rand()/RAND_MAX+1.0)) int main (int argc, char **argv) { diff --git a/files.c b/files.c --- a/files.c +++ b/files.c @@ -14,7 +14,7 @@ #define MAXDIRS 1000 #define MAXFILES 1000 -#define GETRANDOM(max) (1+(int)((float)max*rand()/RAND_MAX+1.0)) +#define GETRANDOM(max) (1+(int)((float)(max)*rand()/RAND_MAX+1.0)) char *GetRandomNumberString () { diff --git a/sort.c b/sort.c --- a/sort.c +++ b/sort.c @@ -27,7 +27,12 @@ void swap (int *v, int i, int j) { - int old = v[i]; + int old; + + if (i == j) + return; + + old = v[i]; v[i] = v[j]; v[j] = old; diff --git a/tree.c b/tree.c --- a/tree.c +++ b/tree.c @@ -7,7 +7,7 @@ #include #include -#define GETRANDOM(max) (1+(int)((float)max*rand()/RAND_MAX+1.0)) +#define GETRANDOM(max) (1+(int)((float)(max)*rand()/RAND_MAX+1.0)) struct T { int data; diff --git a/vector.cc b/vector.cc --- a/vector.cc +++ b/vector.cc @@ -7,7 +7,7 @@ #include #include -#define GETRANDOM(max) (1+(int)((float)max*rand()/RAND_MAX+1.0)) +#define GETRANDOM(max) (1+(int)((float)(max)*rand()/RAND_MAX+1.0)) #define MAX 6 static int refCounter = 0;