]> git.mxchange.org Git - flightgear.git/blobdiff - DEM/dem.cxx
Abort out early when reading the "A" record if it doesn't look like
[flightgear.git] / DEM / dem.cxx
index 821f23fc3e95f86b35dfe2e753db03bc393efbd4..b76f183b1be6292daabe3c342c916c364a158e2a 100644 (file)
@@ -105,7 +105,7 @@ int fgDEM::open ( char *file ) {
        // fd = stdin;
        fd = gzdopen(STDIN_FILENO, "r");
     } else {
-       if ( (fd = gzopen(file, "r")) == NULL ) {
+       if ( (fd = gzopen(file, "rb")) == NULL ) {
            printf("Cannot gzopen %s\n", file);
            return(0);
        }
@@ -125,7 +125,7 @@ int fgDEM::close ( void ) {
 
 
 // return next token from input stream
-static void next_token(gzFile *fd, char *token) {
+static void next_token(gzFile fd, char *token) {
     int i, result;
     char c;
 
@@ -152,7 +152,7 @@ static void next_token(gzFile *fd, char *token) {
 
 
 // return next integer from input stream
-static int next_int(gzFile *fd) {
+static int next_int(gzFile fd) {
     char token[80];
 
     next_token(fd, token);
@@ -161,7 +161,7 @@ static int next_int(gzFile *fd) {
 
 
 // return next double from input stream
-static double next_double(gzFile *fd) {
+static double next_double(gzFile fd) {
     char token[80];
 
     next_token(fd, token);
@@ -170,7 +170,7 @@ static double next_double(gzFile *fd) {
 
 
 // return next exponential num from input stream
-static int next_exp(gzFile *fd) {
+static int next_exp(gzFile fd) {
     char token[80];
     double mantissa;
     int exp, acc;
@@ -198,7 +198,7 @@ static int next_exp(gzFile *fd) {
 
 
 // read and parse DEM "A" record
-void fgDEM::read_a_record( void ) {
+int fgDEM::read_a_record( void ) {
     int i, inum;
     double dnum;
     char name[144];
@@ -225,6 +225,10 @@ void fgDEM::read_a_record( void ) {
     inum = next_int(fd);
     printf("    DEM level code = %d\n", inum);
 
+    if ( inum > 3 ) {
+       return(0);
+    }
+
     // Pattern code, 1 indicates a regular elevation pattern
     inum = next_int(fd);
     printf("    Pattern code = %d\n", inum);
@@ -331,6 +335,8 @@ void fgDEM::read_a_record( void ) {
     // number of profiles
     dem_num_profiles = cols = next_int(fd);
     printf("    Expecting %d profiles\n", dem_num_profiles);
+
+    return(1);
 }
 
 
@@ -375,9 +381,11 @@ void fgDEM::read_b_record( void ) {
 int fgDEM::parse( void ) {
     int i;
 
-    cur_row = 0;
+    cur_col = 0;
 
-    read_a_record();
+    if ( !read_a_record() ) {
+       return(0);
+    }
 
     for ( i = 0; i < dem_num_profiles; i++ ) {
        // printf("Ready to read next b record\n");
@@ -391,7 +399,7 @@ int fgDEM::parse( void ) {
 
     printf("    Done parsing\n");
 
-    return(0);
+    return(1);
 }
 
 
@@ -772,6 +780,19 @@ fgDEM::~fgDEM( void ) {
 
 
 // $Log$
+// Revision 1.7  1998/06/05 18:14:39  curt
+// Abort out early when reading the "A" record if it doesn't look like
+// a proper DEM file.
+//
+// Revision 1.6  1998/05/02 01:49:21  curt
+// Fixed a bug where the wrong variable was being initialized.
+//
+// Revision 1.5  1998/04/25 15:00:32  curt
+// Changed "r" to "rb" in gzopen() options.  This fixes bad behavior in win32.
+//
+// Revision 1.4  1998/04/22 13:14:46  curt
+// Fixed a bug in zlib usage.
+//
 // Revision 1.3  1998/04/18 03:53:05  curt
 // Added zlib support.
 //