From 2d35e9f64f547cb4fe7f97c69b4aca6bfad8f5f3 Mon Sep 17 00:00:00 2001
From: Nick Clifton <nickc@redhat.com>
Date: Fri, 24 Sep 1999 09:03:49 +0000
Subject: [PATCH] Make sure that sensible values are extracted from a raw
 header.

---
 gprof/ChangeLog | 5 +++++
 gprof/gmon_io.c | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/gprof/ChangeLog b/gprof/ChangeLog
index 2f490fbb6d4..ae5e9f439f4 100644
--- a/gprof/ChangeLog
+++ b/gprof/ChangeLog
@@ -1,3 +1,8 @@
+1999-09-24  Nick Clifton  <nickc@cygnus.com>
+
+	* gmon_io.c (gmon_out_read): Make sure that sensible values
+	are extracted from a raw header.
+
 1999-08-06  Ian Lance Taylor  <ian@zembu.com>
 
 	From Brad Lucier <lucier@math.purdue.edu>:
diff --git a/gprof/gmon_io.c b/gprof/gmon_io.c
index 067323cbc9f..7e0a1a0a81b 100644
--- a/gprof/gmon_io.c
+++ b/gprof/gmon_io.c
@@ -251,6 +251,15 @@ DEFUN (gmon_out_read, (filename), const char *filename)
 	   printf ("[gmon_out_read] samp_bytes %d hist_num_bins %d\n",
 		   samp_bytes, hist_num_bins));
 
+      /* Make sure that we have sensible values.  */
+      if (samp_bytes < 0 || lowpc > highpc)
+        {
+          fprintf (stderr, 
+	    _("%s: file '%s' does not appear to be in gmon.out format\n"),
+	    whoami, filename);
+          done (1);
+        }
+
       if (hist_num_bins)
 	{
 	  ++nhist;