diff --git a/binutils/bfdtest1.c b/binutils/bfdtest1.c
index 9714998fa6b..ef68732e37f 100644
--- a/binutils/bfdtest1.c
+++ b/binutils/bfdtest1.c
@@ -53,6 +53,8 @@ main (int argc, char **argv)
        last = next)
     {
       next = bfd_openr_next_archived_file (archive, last);
+      if (next == last)
+	die ("next_archived_file");
       bfd_close (last);
       count++;
     }
@@ -62,6 +64,8 @@ main (int argc, char **argv)
        last = next)
     {
       next = bfd_openr_next_archived_file (archive, last);
+      if (next == last)
+	die ("next_archived_file");
       bfd_close (last);
       count--;
     }
