[Gridflow-cvs] [svn] commit: r4619 - /trunk/format/main.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Sun Nov 1 16:16:49 EST 2009


Author: matju
Date: Sun Nov  1 16:16:48 2009
New Revision: 4619

Log:
fix gridflow.h problem and added some error checks in [#in grid]

Modified:
    trunk/format/main.c

Modified: trunk/format/main.c
==============================================================================
--- trunk/format/main.c (original)
+++ trunk/format/main.c Sun Nov  1 16:16:48 2009
@@ -2,7 +2,7 @@
 	$Id$
 
 	GridFlow
-	Copyright (c) 2001-2008 by Mathieu Bouchard
+	Copyright (c) 2001-2009 by Mathieu Bouchard
 
 	This program is free software; you can redistribute it and/or
 	modify it under the terms of the GNU General Public License
@@ -21,7 +21,7 @@
 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
-#include "../gridflow.h.fcs"
+#include "../src/gridflow.hxx.fcs"
 #include <string>
 #include <map>
 #include <errno.h>
@@ -175,7 +175,7 @@
 	if (headerless_dim) {
 		dim = headerless_dim;
 	} else {
-		fread(&head,1,8,f);
+		if (fread(&head,1,8,f)<8) RAISE("can't read header");
 		uint8 *m = (uint8 *)head.magic;
 		if (strncmp((char *)m,"\x7fgrid",5)==0) endian=1; else
 		if (strncmp((char *)m,"\x7fGRID",5)==0) endian=0; else
@@ -193,13 +193,14 @@
 		if (head.reserved!=0) RAISE("unsupported grid reserved field %d in file",head.reserved);
 		if (head.dimn>16) RAISE("unsupported grid number of dimensions %d in file",head.dimn);
 		int32 dimv[head.dimn];
-		fread(dimv,head.dimn,4,f);
+		;
+		if (fread(dimv,1,head.dimn*4,f)<size_t(head.dimn*4)) RAISE("can't read dimension list");
 		if (endian != is_le()) swap32(head.dimn,(uint32 *)dimv);
 		dim = new Dim(head.dimn,dimv);
 	}
 	GridOutlet out(this,0,dim,nt);
 	long nn = dim->prod();
-#define FOO(T) {T data[nn]; fread(data,nn,sizeof(T),f); out.send(nn,(T *)data);}
+#define FOO(T) {T data[nn]; if (fread(data,1,nn*sizeof(T),f)<nn*sizeof(T)) RAISE("can't read grid data (body)"); out.send(nn,(T *)data);}
 TYPESWITCH(nt,FOO,)
 #undef FOO
 	SUPER;



More information about the Gridflow-cvs mailing list