altoslib: Catch a couple null pointers in AltosConfigTD
authorKeith Packard <keithp@keithp.com>
Mon, 1 Sep 2014 23:23:42 +0000 (18:23 -0500)
committerKeith Packard <keithp@keithp.com>
Mon, 1 Sep 2014 23:23:42 +0000 (18:23 -0500)
When messing with TD, I hit a couple of paths that could try to
dereference null pointers. Check for those.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosConfigTD.java

index 4389e49b0c57ac431512a5544b3243441390afa0..9020ed9ddc874f0d652c39aa491a74b641c2ceb2 100644 (file)
@@ -223,8 +223,10 @@ public class AltosConfigTD implements ActionListener {
                                        if (!config_version.get().equals("0.0"))
                                                break;
                                        been_there = true;
-                                       config.serial_line.printf("C\n ");
-                                       config.serial_line.flush_input();
+                                       if (config != null && config.serial_line != null) {
+                                               config.serial_line.printf("C\n ");
+                                               config.serial_line.flush_input();
+                                       }
                                }
                        } catch (InterruptedException ie) {
                        }
@@ -277,8 +279,10 @@ public class AltosConfigTD implements ActionListener {
        }
 
        void abort() {
-               serial_line.close();
-               serial_line = null;
+               if (serial_line != null) {
+                       serial_line.close();
+                       serial_line = null;
+               }
                JOptionPane.showMessageDialog(owner,
                                              String.format("Connection to \"%s\" failed",
                                                            device.toShortString()),