From fc2bf98122cc81aac395a64a8203c9bb026bb9e1 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 16 Oct 2004 11:24:48 +0000 Subject: [PATCH] prevent a segmentation error under certain circumstances. --- src/Network/generic.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index 66e0fac19..c25e82580 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -59,11 +59,13 @@ FGGeneric::FGGeneric(string& config) { _out_message.clear(); SGPropertyNode *output = root.getNode("generic/output"); - read_config(output, _out_message); + if (output) + read_config(output, _out_message); _in_message.clear(); SGPropertyNode *input = root.getNode("generic/input"); - read_config(input, _in_message); + if (input) + read_config(input, _in_message); } FGGeneric::~FGGeneric() { @@ -126,13 +128,16 @@ bool FGGeneric::gen_message() { bool FGGeneric::parse_message() { char *p2, *p1 = buf; double val; - int i = 0; + int i = -1; - while (p1 && strcmp(p1, line_separator.c_str())) { + while ((++i < _in_message.size()) && + p1 && strcmp(p1, line_separator.c_str())) { p2 = strstr(p1, var_separator.c_str()); - if (p2) - *(p2++) = 0; + if (p2) { + *p2 = 0; + p2 += var_separator.length(); + } switch (_in_message[i].type) { case FG_INT: @@ -141,7 +146,7 @@ bool FGGeneric::parse_message() { break; case FG_BOOL: - _in_message[i].prop->setBoolValue( atoi(p1) != 0 ); + _in_message[i].prop->setBoolValue( atof(p1) != 0.0 ); break; case FG_DOUBLE: @@ -154,7 +159,6 @@ bool FGGeneric::parse_message() { } p1 = p2; - i++; } return true;