]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
2005-04-12 Ulrich Drepper <drepper@redhat.com>
authorRoland McGrath <roland@gnu.org>
Mon, 18 Jul 2005 02:39:13 +0000 (02:39 +0000)
committerRoland McGrath <roland@gnu.org>
Mon, 18 Jul 2005 02:39:13 +0000 (02:39 +0000)
[BZ #1090]
* stdlib/random_r.c (__initstate_r): Don't use non-existing state.
* string/tst-strfry.c: New file.
* string/Makefile (tests): Add tst-strfry.

stdlib/random_r.c
string/Makefile
string/tst-strfry.c [new file with mode: 0644]

index e955ea576a5e1ed5606358a4dd2771bd37c78d26..404006f2cd32e1c28f586732dab0dfa9efe9dffc 100644 (file)
@@ -236,23 +236,20 @@ __initstate_r (seed, arg_state, n, buf)
      size_t n;
      struct random_data *buf;
 {
-  int type;
-  int degree;
-  int separation;
-  int32_t *state;
-  int old_type;
-  int32_t *old_state;
-
   if (buf == NULL)
     goto fail;
 
-  old_type = buf->rand_type;
-  old_state = buf->state;
-  if (old_type == TYPE_0)
-    old_state[-1] = TYPE_0;
-  else
-    old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
+  int32_t *old_state = buf->state;
+  if (old_state != NULL)
+    {
+      int old_type = buf->rand_type;
+      if (old_type == TYPE_0)
+       old_state[-1] = TYPE_0;
+      else
+       old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
+    }
 
+  int type;
   if (n >= BREAK_3)
     type = n < BREAK_4 ? TYPE_3 : TYPE_4;
   else if (n < BREAK_1)
@@ -267,13 +264,13 @@ __initstate_r (seed, arg_state, n, buf)
   else
     type = n < BREAK_2 ? TYPE_1 : TYPE_2;
 
-  degree = random_poly_info.degrees[type];
-  separation = random_poly_info.seps[type];
+  int degree = random_poly_info.degrees[type];
+  int separation = random_poly_info.seps[type];
 
   buf->rand_type = type;
   buf->rand_sep = separation;
   buf->rand_deg = degree;
-  state = &((int32_t *) arg_state)[1]; /* First location.  */
+  int32_t *state = &((int32_t *) arg_state)[1];        /* First location.  */
   /* Must set END_PTR before srandom.  */
   buf->end_ptr = &state[degree];
 
index 66469f586ed7ae9bf800f0643607e045e7681f46..7a77e35732aa78549c725b1162b15a885501b44d 100644 (file)
@@ -52,7 +52,7 @@ strop-tests   := memchr memcmp memcpy memmove mempcpy memset memccpy  \
 tests          := tester inl-tester noinl-tester testcopy test-ffs     \
                   tst-strlen stratcliff tst-svc tst-inlcall            \
                   bug-strncat1 bug-strspn1 bug-strpbrk1 tst-bswap      \
-                  tst-strtok tst-strxfrm bug-strcoll1                  \
+                  tst-strtok tst-strxfrm bug-strcoll1 tst-strfry       \
                   $(addprefix test-,$(strop-tests))
 distribute     := memcopy.h pagecopy.h tst-svc.expect test-string.h
 
diff --git a/string/tst-strfry.c b/string/tst-strfry.c
new file mode 100644 (file)
index 0000000..2b40a39
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <string.h>
+
+static int
+do_test (void)
+{
+  char str[] = "this is a test";
+
+  strfry (str);
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"