From 9e66194dca9c669a227a9b8b0516917e9dcda896 Mon Sep 17 00:00:00 2001 From: daveluff Date: Thu, 9 Oct 2003 21:37:26 +0000 Subject: [PATCH] Fix a possible endless loop due to insufficient space in a char array for some messages --- src/ATC/transmissionlist.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ATC/transmissionlist.cxx b/src/ATC/transmissionlist.cxx index 7f5b09f62..e09dc6fd1 100644 --- a/src/ATC/transmissionlist.cxx +++ b/src/ATC/transmissionlist.cxx @@ -142,7 +142,7 @@ bool FGTransmissionList::query_station( const int &station, FGTransmission *t, string FGTransmissionList::gen_text(const int &station, const TransCode code, const TransPar &tpars, const bool ttext ) { - const int cmax = 100; + const int cmax = 300; string message; char tag[4]; char crej = '@'; @@ -167,6 +167,7 @@ string FGTransmissionList::gen_text(const int &station, const TransCode code, else message = current->get_menutext(); strcpy( &mes[0], message.c_str() ); + int check = 0; // If mes gets overflowed the while loop can go infinite while ( strchr(&mes[0], crej) != NULL ) { pos = strchr( &mes[0], crej ); bcopy(pos, &tag[0], 3); @@ -240,6 +241,12 @@ string FGTransmissionList::gen_text(const int &station, const TransCode code, } strcat( &dum[0], &mes[len+3] ); strcpy( &mes[0], &dum[0] ); + + ++check; + if(check > 10) { + SG_LOG(SG_ATC, SG_WARN, "WARNING: Possibly endless loop terminated in FGTransmissionlist::gen_text(...)"); + break; + } } //cout << mes << endl;