changeset 7352:fab9bc33b949

[project @ 2008-01-07 18:54:45 by jwe]
author jwe
date Mon, 07 Jan 2008 18:54:45 +0000
parents 8470a6b0b769
children 516ddd88e45a
files scripts/ChangeLog scripts/miscellaneous/copyfile.m scripts/miscellaneous/movefile.m src/ChangeLog src/gripes.cc src/gripes.h src/oct-stream.cc
diffstat 7 files changed, 53 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Jan 07 17:57:24 2008 +0000
+++ b/scripts/ChangeLog	Mon Jan 07 18:54:45 2008 +0000
@@ -1,3 +1,8 @@
+2008-01-07  John W. Eaton  <jwe@octave.org>
+
+	* miscellaneous/copyfile.m, miscellaneous/movefile.m:
+	Error if glob call fails to match any files.
+
 2008-01-04  Thomas Treichl  <Thomas.Treichl@gmx.net>
 
 	* strings/strtrim.m: Doc fix.
--- a/scripts/miscellaneous/copyfile.m	Mon Jan 07 17:57:24 2008 +0000
+++ b/scripts/miscellaneous/copyfile.m	Mon Jan 07 18:54:45 2008 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 2005, 2006, 2007 John W. Eaton
+## Copyright (C) 2005, 2006, 2007, 2008 John W. Eaton
 ##
 ## This file is part of Octave.
 ##
@@ -76,6 +76,9 @@
     
     ## Protect the file name(s).
     f1 = glob (f1);
+    if (isempty (f1))
+      error ("copyfile: no files to move");
+    endif
     p1 = sprintf ("\"%s\" ", f1{:});
     p2 = tilde_expand (f2);
 
--- a/scripts/miscellaneous/movefile.m	Mon Jan 07 17:57:24 2008 +0000
+++ b/scripts/miscellaneous/movefile.m	Mon Jan 07 18:54:45 2008 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 2005, 2006, 2007 John W. Eaton
+## Copyright (C) 2005, 2006, 2007, 2008 John W. Eaton
 ##
 ## This file is part of Octave.
 ##
@@ -75,6 +75,9 @@
     
     ## Protect the file name(s).
     f1 = glob (f1);
+    if (isempty (f1))
+      error ("movefile: no files to move");
+    endif
     p1 = sprintf ("\"%s\" ", f1{:});
     p2 = tilde_expand (f2);
 
--- a/src/ChangeLog	Mon Jan 07 17:57:24 2008 +0000
+++ b/src/ChangeLog	Mon Jan 07 18:54:45 2008 +0000
@@ -1,5 +1,14 @@
 2008-01-07  John W. Eaton  <jwe@octave.org>
 
+	* gripes.cc (gripe_wrong_type_arg (const std::string&, const
+	octave_value&, bool)): New function.
+	* gripes.h: Provide decl.
+
+	* oct-stream.cc (printf_value_cache::printf_value_cache):
+	Reject structs, cells, objects, and lists.
+	(octave_base_stream::do_printf): Quit early if printf_value_cache
+	constructor fails.
+
 	* parse.y (make_anon_fcn_handle): Don't attempt to convert
 	expression to assignment to __retval__.
 
--- a/src/gripes.cc	Mon Jan 07 17:57:24 2008 +0000
+++ b/src/gripes.cc	Mon Jan 07 18:54:45 2008 +0000
@@ -156,6 +156,13 @@
 }
 
 void
+gripe_wrong_type_arg (const std::string& name, const octave_value& tc,
+		      bool is_error)
+{
+  gripe_wrong_type_arg (name.c_str (), tc, is_error);
+}
+
+void
 gripe_wrong_type_arg_for_unary_op (const octave_value& op)
 {
   std::string type = op.type_name ();
--- a/src/gripes.h	Mon Jan 07 17:57:24 2008 +0000
+++ b/src/gripes.h	Mon Jan 07 18:54:45 2008 +0000
@@ -91,6 +91,10 @@
 		      bool is_error = true);
 
 extern OCTINTERP_API void
+gripe_wrong_type_arg (const std::string& name, const octave_value& tc,
+		      bool is_error = true);
+
+extern OCTINTERP_API void
 gripe_wrong_type_arg_for_unary_op (const octave_value& op);
 
 extern OCTINTERP_API void
--- a/src/oct-stream.cc	Mon Jan 07 17:57:24 2008 +0000
+++ b/src/oct-stream.cc	Mon Jan 07 18:54:45 2008 +0000
@@ -47,6 +47,7 @@
 #include "quit.h"
 
 #include "error.h"
+#include "gripes.h"
 #include "input.h"
 #include "oct-stdstrm.h"
 #include "oct-stream.h"
@@ -2276,10 +2277,23 @@
 
   enum state { ok, conversion_error };
 
-  printf_value_cache (const octave_value_list& args)
+  printf_value_cache (const octave_value_list& args, const std::string& who)
     : values (args), val_idx (0), elt_idx (0),
       n_vals (values.length ()), n_elts (0), data (0),
-      curr_state (ok) { }
+      curr_state (ok)
+  {
+    for (octave_idx_type i = 0; i < values.length (); i++)
+      {
+	octave_value val = values(i);
+
+	if (val.is_map () || val.is_cell () || val.is_object ()
+	    || val.is_list ())
+	  {
+	    gripe_wrong_type_arg (who, val);
+	    break;
+	  }
+      }
+  }
 
   ~printf_value_cache (void) { }
 
@@ -2527,7 +2541,10 @@
 
       const printf_format_elt *elt = fmt_list.first ();
 
-      printf_value_cache val_cache (args);
+      printf_value_cache val_cache (args, who);
+
+      if (error_state)
+	return retval;
 
       for (;;)
 	{