X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FGUI%2FAirportList.cxx;h=6e4570b6c9236dd0def5c0c7585791245a871fc3;hb=4a68c2ffb0909b07dc094298e005522cef5162bc;hp=43cee70ab522fd361d336f6c78c54a2e5dbdc6a4;hpb=8b2cfb515befa803ed86a5cc458717d2e2c240c0;p=flightgear.git diff --git a/src/GUI/AirportList.cxx b/src/GUI/AirportList.cxx index 43cee70ab..6e4570b6c 100644 --- a/src/GUI/AirportList.cxx +++ b/src/GUI/AirportList.cxx @@ -1,3 +1,5 @@ +#include // strncpy() + #include
#include @@ -15,10 +17,15 @@ 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", + snprintf(buf, 1023, "%s %s\0", airport->id.c_str(), airport->name.c_str()); - _content[i] = strndup(buf, 1023); + + 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+1] = '\0'; } _content[_nAirports] = 0; newList(_content);