Update.
authorUlrich Drepper <drepper@redhat.com>
Wed, 11 Apr 2001 21:29:54 +0000 (21:29 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 11 Apr 2001 21:29:54 +0000 (21:29 +0000)
2001-04-11  Ulrich Drepper  <drepper@redhat.com>

* cancel.c (_pthread_cleanup_push): Catch invalid __prev buffer
and remove it.
(_pthread_cleanup_push_defer): Likewise.

* tst-cancel.c (main): Fix loop printing cleanup output.

linuxthreads/ChangeLog
linuxthreads/cancel.c
linuxthreads/tst-cancel.c

index 805e837..47c15c6 100644 (file)
@@ -1,3 +1,11 @@
+2001-04-11  Ulrich Drepper  <drepper@redhat.com>
+
+       * cancel.c (_pthread_cleanup_push): Catch invalid __prev buffer
+       and remove it.
+       (_pthread_cleanup_push_defer): Likewise.
+
+       * tst-cancel.c (main): Fix loop printing cleanup output.
+
 2001-04-10  kaz Kojima  <kkojima@rr.iij4u.or.jp>
 
        * sysdeps/sh/pspinlock.c (__pthread_spin_lock): Fix a reverse
index ed67a68..32ad17c 100644 (file)
@@ -125,6 +125,18 @@ void _pthread_cleanup_push(struct _pthread_cleanup_buffer * buffer,
   buffer->__routine = routine;
   buffer->__arg = arg;
   buffer->__prev = THREAD_GETMEM(self, p_cleanup);
+  if (buffer->__prev != NULL)
+    {
+#if _STACK_GROWS_DOWN
+      if ((char *) buffer >= (char *) buffer->__prev)
+       buffer->__prev = NULL;
+#elif _STACK_GROWS_UP
+      if ((char *) buffer <= (char *) buffer->__prev)
+       buffer->__prev = NULL;
+#else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+#endif
+    }
   THREAD_SETMEM(self, p_cleanup, buffer);
 }
 
@@ -144,6 +156,16 @@ void _pthread_cleanup_push_defer(struct _pthread_cleanup_buffer * buffer,
   buffer->__arg = arg;
   buffer->__canceltype = THREAD_GETMEM(self, p_canceltype);
   buffer->__prev = THREAD_GETMEM(self, p_cleanup);
+  if (buffer->__prev != NULL)
+    {
+#if _STACK_GROWS_DOWN
+      if ((char *) buffer >= (char *) buffer->__prev)
+       buffer->__prev = NULL;
+#elif _STACK_GROWS_UP
+      if ((char *) buffer <= (char *) buffer->__prev)
+       buffer->__prev = NULL;
+#endif
+    }
   THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_DEFERRED);
   THREAD_SETMEM(self, p_cleanup, buffer);
 }
@@ -174,8 +196,6 @@ void __pthread_perform_cleanup(char *currentframe)
 #elif _STACK_GROWS_UP
       if ((char *) c >= currentframe)
        break;
-#else
-# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
 #endif
       c->__routine(c->__arg);
     }
index da70d12..75d6c0d 100644 (file)
@@ -142,7 +142,7 @@ main (void)
       while (1)
        {
          ssize_t n = read (fd, buf, sizeof buf);
-         if (n < 0)
+         if (n <= 0)
            break;
          write (STDOUT_FILENO, buf, n);
        }