getrandom macro fixed
the getrandom expanded to the wrong value when dealing with expressions.
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- 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;