getrandom macro fixed
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:50:39 +0200
changeset 74 829976007e62
parent 73 d0578510aea1
child 75 a2c32869d4d5
getrandom macro fixed the getrandom expanded to the wrong value when dealing with expressions. committer: Markus Bröker <mbroeker@largo.homelinux.org>
Makefile
crypt.c
files.c
sort.c
tree.c
vector.cc
--- 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:
--- a/crypt.c
+++ b/crypt.c
@@ -8,7 +8,7 @@
 #include <time.h>
 #include <crypt.h>
 
-#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)
 {
--- 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 ()
 {
--- 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;
--- a/tree.c
+++ b/tree.c
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include <time.h>
 
-#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;
--- a/vector.cc
+++ b/vector.cc
@@ -7,7 +7,7 @@
 #include <cmath>
 #include <ctime>
 
-#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;