Module Name:    src
Committed By:   christos
Date:           Mon Apr 18 15:23:28 UTC 2011

Modified Files:
        src/external/historical/nawk/dist: main.c run.c

Log Message:
PR/44876: Aleksey Cheusov: awk: incorrect return value of function srand()
Make it return the value of the previous random seed as the standard mandates.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/historical/nawk/dist/main.c
cvs rdiff -u -r1.2 -r1.3 src/external/historical/nawk/dist/run.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/main.c
diff -u src/external/historical/nawk/dist/main.c:1.4 src/external/historical/nawk/dist/main.c:1.5
--- src/external/historical/nawk/dist/main.c:1.4	Mon Oct 18 11:58:05 2010
+++ src/external/historical/nawk/dist/main.c	Mon Apr 18 11:23:28 2011
@@ -42,6 +42,7 @@
 extern	int	nfields;
 
 int	dbg	= 0;
+unsigned int srand_seed;
 char	*cmdname;	/* gets argv[0] for error messages */
 extern	FILE	*yyin;	/* lex input file */
 char	*lexprog;	/* points to program argument if it exists */
@@ -122,6 +123,10 @@
 #else
 	(void)signal(SIGFPE, fpecatch);
 #endif
+	/* Set and keep track of the random seed */
+	srand_seed = 1;
+	srand(srand_seed);
+
 	yyin = NULL;
 	symtab = makesymtab(NSYMTAB/NSYMTAB);
 	while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {

Index: src/external/historical/nawk/dist/run.c
diff -u src/external/historical/nawk/dist/run.c:1.2 src/external/historical/nawk/dist/run.c:1.3
--- src/external/historical/nawk/dist/run.c:1.2	Thu Aug 26 10:55:20 2010
+++ src/external/historical/nawk/dist/run.c	Mon Apr 18 11:23:28 2011
@@ -74,6 +74,7 @@
 
 jmp_buf env;
 extern	int	pairstack[];
+extern	unsigned int srand_seed;
 
 Node	*winner = NULL;	/* root of parse tree */
 Cell	*tmps;		/* free temporary cells for execution */
@@ -1546,6 +1547,7 @@
 	Cell *x, *y;
 	Awkfloat u;
 	int t, sz;
+	unsigned int tmp;
 	char *buf, *fmt;
 	Node *nextarg;
 	FILE *fp;
@@ -1598,7 +1600,9 @@
 			u = time((time_t *)0);
 		else
 			u = getfval(x);
-		srand((unsigned int) u);
+		srand(tmp = (unsigned int) u);
+		u = srand_seed;
+		srand_seed = tmp;
 		break;
 	case FTOUPPER:
 	case FTOLOWER:

Reply via email to