]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/AirportList.cxx
Fix line endings
[flightgear.git] / src / GUI / AirportList.cxx
index 3f97342dee4707a1b554b425d8770b8b0af161dc..16f9785d037664420a3c0199f7459286111c6b5c 100644 (file)
@@ -1,3 +1,5 @@
+#include <string.h>    // strncpy()
+
 #include <Main/globals.hxx>
 #include <Airports/simple.hxx>
 
@@ -14,13 +16,16 @@ AirportList::AirportList (int x, int y, int width, int height)
 
     _content = new char *[_nAirports+1];
     for (int i = 0; i < _nAirports; i++) {
-        const FGAirport * airport = _airports->getAirport(i);
-        snprintf(buf, 1023, "%s  %s\n",
-                 airport->id.c_str(),
-                 airport->name.c_str());
-        int str_len = strlen(buf);
-        _content[i] = new char[(str_len > 1023) ? 1024 : str_len];
-        strncpy(_content[i], buf, 1023);
+        const FGAirport *airport = _airports->getAirport(i);
+        snprintf(buf, 1023, "%s  %s",
+                 airport->getId().c_str(),
+                 airport->getName().c_str());
+
+        unsigned int buf_len = (strlen(buf) > 1023) ? 1023 : strlen(buf);
+        
+        _content[i] = new char[buf_len+1];
+        memcpy(_content[i], buf, buf_len);
+        _content[i][buf_len] = '\0';
     }
     _content[_nAirports] = 0;
     newList(_content);
@@ -36,9 +41,9 @@ AirportList::~AirportList ()
 }
 
 char *
-AirportList::getStringValue ()
+AirportList::getListStringValue ()
 {
-    return (char *)_airports->getAirport(getIntegerValue())->id.c_str();
+    return (char *)_airports->getAirport(getListIntegerValue())->getId().c_str();
 }
 
 // end of AirportList.cxx