diff src/ov-re-mat.cc @ 4100:ed0090ecf80f

[project @ 2002-10-11 16:37:45 by jwe]
author jwe
date Fri, 11 Oct 2002 16:37:45 +0000
parents 47d3baea432d
children cbac6756967e
line wrap: on
line diff
--- a/src/ov-re-mat.cc	Thu Oct 10 06:23:03 2002 +0000
+++ b/src/ov-re-mat.cc	Fri Oct 11 16:37:45 2002 +0000
@@ -28,6 +28,8 @@
 #include <config.h>
 #endif
 
+#include <climits>
+
 #include <iostream>
 
 #include "lo-ieee.h"
@@ -46,6 +48,10 @@
 #include "pr-output.h"
 #include "variables.h"
 
+#if ! defined (UCHAR_MAX)
+#define UCHAR_MAX 255
+#endif
+
 template class octave_base_matrix<Matrix>;
 
 DEFINE_OCTAVE_ALLOCATOR (octave_matrix);
@@ -125,6 +131,8 @@
       else
 	{
 	  charMatrix chm (nr, nc);
+	  
+	  bool warned = false;
 
 	  for (int j = 0; j < nc; j++)
 	    {
@@ -139,11 +147,23 @@
 		    }
 		  else
 		    {
-		      // XXX FIXME XXX -- warn about out of range
-		      // conversions?
+		      int ival = NINT (d);
+
+		      if (ival < 0 || ival > UCHAR_MAX)
+			{
+			  // XXX FIXME XXX -- is there something
+			  // better we could do?
+
+			  ival = 0;
 
-		      int ival = NINT (d);
-		      chm (i, j) = (char) ival;
+			  if (! warned)
+			    {
+			      ::warning ("range error for conversion to character value");
+			      warned = true;
+			    }
+			}
+
+		      chm (i, j) = static_cast<char> (ival);
 		    }
 		}
 	    }