]> git.mxchange.org Git - flightgear.git/commitdiff
Fix fgviewer segfault
authorJeff Taylor <jefftaylor42@gmail.com>
Sat, 22 May 2010 20:30:03 +0000 (13:30 -0700)
committerTim Moore <timoore33@gmail.com>
Sun, 23 May 2010 18:13:09 +0000 (20:13 +0200)
fgviewer crashes when reading weird channel options (which it doesn't use).
Here is a patch which fixes this by adding a pointer check.

src/Main/options.cxx

index bededfb71e43ed8cbbfe535954bb60a1f5d57440..a994f59537670858180cba5824efeb92fa937020 100644 (file)
@@ -530,6 +530,14 @@ parse_fov( const string& arg ) {
 
 static bool
 add_channel( const string& type, const string& channel_str ) {
+    // This check is neccessary to prevent fgviewer from segfaulting when given
+    // weird options. (It doesn't run the full initailization)
+    if(!globals->get_channel_options_list())
+    {
+        SG_LOG(SG_GENERAL, SG_ALERT, "Option " << type << "=" << channel_str
+                                     << " ignored.");
+        return false;
+    }
     SG_LOG(SG_GENERAL, SG_INFO, "Channel string = " << channel_str );
     globals->get_channel_options_list()->push_back( type + "," + channel_str );
     return true;
@@ -1572,6 +1580,7 @@ parse_option (const string& arg)
                     }
                     break;
                 case OPTION_CHANNEL:
+                    // XXX return value of add_channel should be checked?
                     if ( pt->has_param && !arg_value.empty() ) {
                         add_channel( pt->option, arg_value );
                     } else if ( !pt->has_param && arg_value.empty() ) {