1
0
Fork 0

Jim Wilson:

This patch exposes the nav_id--Navaid (VOR/ILS) IDs--in the property tree for use in EFIS displays.  Both the string and individual integer (char) values are published.


Erik Hofman:
I have converted all sprintf() functions in navcom.cxx into snprintf() for some extra securety.
This commit is contained in:
ehofman 2003-07-03 08:51:19 +00:00
parent 709f57fe91
commit a1968ecb95
2 changed files with 60 additions and 36 deletions

View file

@ -95,29 +95,30 @@ FGNavCom::init ()
// We assume that index is valid now (it must be set before init() // We assume that index is valid now (it must be set before init()
// is called.) // is called.)
char propname[256]; char propname[256];
// FIXME: Get rid of snprintf
sprintf( propname, "/systems/electrical/outputs/navcom[%d]", index ); snprintf(propname, 256, "/systems/electrical/outputs/navcom[%d]", index);
// default to true in case no electrical system defined. // default to true in case no electrical system defined.
fgSetDouble( propname, 60.0 ); fgSetDouble( propname, 60.0 );
bus_power = fgGetNode( propname, true ); bus_power = fgGetNode( propname, true );
sprintf( propname, "/instrumentation/comm[%d]/servicable", index ); snprintf(propname, 256, "/instrumentation/comm[%d]/servicable", index);
com_servicable = fgGetNode( propname, true ); com_servicable = fgGetNode( propname, true );
com_servicable->setBoolValue( true ); com_servicable->setBoolValue( true );
sprintf( propname, "/instrumentation/nav[%d]/servicable", index ); snprintf(propname, 256, "/instrumentation/nav[%d]/servicable", index);
nav_servicable = fgGetNode( propname, true ); nav_servicable = fgGetNode( propname, true );
nav_servicable->setBoolValue( true ); nav_servicable->setBoolValue( true );
sprintf( propname, "/instrumentation/vor[%d]/cdi/servicable", index ); snprintf(propname, 256, "/instrumentation/vor[%d]/cdi/servicable", index);
cdi_servicable = fgGetNode( propname, true ); cdi_servicable = fgGetNode( propname, true );
cdi_servicable->setBoolValue( true ); cdi_servicable->setBoolValue( true );
sprintf( propname, "/instrumentation/vor[%d]/gs/servicable", index ); snprintf(propname, 256, "/instrumentation/vor[%d]/gs/servicable", index);
gs_servicable = fgGetNode( propname, true ); gs_servicable = fgGetNode( propname, true );
gs_servicable->setBoolValue( true ); gs_servicable->setBoolValue( true );
sprintf( propname, "/instrumentation/vor[%d]/to-from/servicable", index ); snprintf(propname, 256, "/instrumentation/vor[%d]/to-from/servicable", index);
tofrom_servicable = fgGetNode( propname, true ); tofrom_servicable = fgGetNode( propname, true );
tofrom_servicable->setBoolValue( true ); tofrom_servicable->setBoolValue( true );
} }
@ -126,79 +127,96 @@ void
FGNavCom::bind () FGNavCom::bind ()
{ {
char propname[256]; char propname[256];
// FIXME: Get rid of snprintf
// User inputs // User inputs
sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index ); snprintf(propname, 256, "/radios/comm[%d]/inputs/power-btn", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_power_btn, &FGNavCom::set_power_btn ); &FGNavCom::get_power_btn, &FGNavCom::set_power_btn );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index ); snprintf(propname, 256, "/radios/comm[%d]/frequencies/selected-mhz", index);
fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq ); fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index ); snprintf(propname, 256, "/radios/comm[%d]/frequencies/standby-mhz", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_comm_alt_freq, &FGNavCom::set_comm_alt_freq ); &FGNavCom::get_comm_alt_freq, &FGNavCom::set_comm_alt_freq );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/comm[%d]/volume", index ); snprintf(propname, 256, "/radios/comm[%d]/volume", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn ); &FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index ); snprintf(propname, 256, "/radios/nav[%d]/frequencies/selected-mhz", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq ); &FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index ); snprintf(propname, 256, "/radios/nav[%d]/frequencies/standby-mhz", index);
fgTie( propname , this, fgTie( propname , this,
&FGNavCom::get_nav_alt_freq, &FGNavCom::set_nav_alt_freq); &FGNavCom::get_nav_alt_freq, &FGNavCom::set_nav_alt_freq);
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index ); snprintf(propname, 256, "/radios/nav[%d]/radials/selected-deg", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_nav_sel_radial, &FGNavCom::set_nav_sel_radial ); &FGNavCom::get_nav_sel_radial, &FGNavCom::set_nav_sel_radial );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/volume", index ); snprintf(propname, 256, "/radios/nav[%d]/volume", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_nav_vol_btn, &FGNavCom::set_nav_vol_btn ); &FGNavCom::get_nav_vol_btn, &FGNavCom::set_nav_vol_btn );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/ident", index ); snprintf(propname, 256, "/radios/nav[%d]/ident", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_nav_ident_btn, &FGNavCom::set_nav_ident_btn ); &FGNavCom::get_nav_ident_btn, &FGNavCom::set_nav_ident_btn );
fgSetArchivable( propname ); fgSetArchivable( propname );
// Radio outputs // Radio outputs
sprintf( propname, "/radios/nav[%d]/audio-btn", index ); snprintf(propname, 256, "/radios/nav[%d]/audio-btn", index);
fgTie( propname, this, fgTie( propname, this,
&FGNavCom::get_audio_btn, &FGNavCom::set_audio_btn ); &FGNavCom::get_audio_btn, &FGNavCom::set_audio_btn );
fgSetArchivable( propname ); fgSetArchivable( propname );
sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index ); snprintf(propname, 256, "/radios/nav[%d]/radials/actual-deg", index);
fgTie( propname, this, &FGNavCom::get_nav_radial ); fgTie( propname, this, &FGNavCom::get_nav_radial );
sprintf( propname, "/radios/nav[%d]/to-flag", index ); snprintf(propname, 256, "/radios/nav[%d]/to-flag", index);
fgTie( propname, this, &FGNavCom::get_nav_to_flag ); fgTie( propname, this, &FGNavCom::get_nav_to_flag );
sprintf( propname, "/radios/nav[%d]/from-flag", index ); snprintf(propname, 256, "/radios/nav[%d]/from-flag", index);
fgTie( propname, this, &FGNavCom::get_nav_from_flag ); fgTie( propname, this, &FGNavCom::get_nav_from_flag );
sprintf( propname, "/radios/nav[%d]/in-range", index ); snprintf(propname, 256, "/radios/nav[%d]/in-range", index);
fgTie( propname, this, &FGNavCom::get_nav_inrange ); fgTie( propname, this, &FGNavCom::get_nav_inrange );
sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index ); snprintf(propname, 256, "/radios/nav[%d]/heading-needle-deflection", index);
fgTie( propname, this, &FGNavCom::get_nav_heading_needle_deflection ); fgTie( propname, this, &FGNavCom::get_nav_heading_needle_deflection );
sprintf( propname, "/radios/nav[%d]/has-gs", index ); snprintf(propname, 256, "/radios/nav[%d]/has-gs", index);
fgTie( propname, this, &FGNavCom::get_nav_has_gs ); fgTie( propname, this, &FGNavCom::get_nav_has_gs );
sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index ); snprintf(propname, 256, "/radios/nav[%d]/gs-needle-deflection", index);
fgTie( propname, this, &FGNavCom::get_nav_gs_needle_deflection ); fgTie( propname, this, &FGNavCom::get_nav_gs_needle_deflection );
snprintf(propname, 256, "/radios/nav[%d]/nav-id", index);
fgTie( propname, this, &FGNavCom::get_nav_id );
// put nav_id characters into seperate properties for instrument displays
snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc1", index);
fgTie( propname, this, &FGNavCom::get_nav_id_c1 );
snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc2", index);
fgTie( propname, this, &FGNavCom::get_nav_id_c2 );
snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc3", index);
fgTie( propname, this, &FGNavCom::get_nav_id_c3 );
snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc4", index);
fgTie( propname, this, &FGNavCom::get_nav_id_c4 );
// end of binding // end of binding
} }
@ -207,33 +225,34 @@ void
FGNavCom::unbind () FGNavCom::unbind ()
{ {
char propname[256]; char propname[256];
// FIXME: Get rid of snprintf
sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index ); snprintf(propname, 256, "/radios/comm[%d]/inputs/power-btn", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index ); snprintf(propname, 256, "/radios/comm[%d]/frequencies/selected-mhz", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index ); snprintf(propname, 256, "/radios/comm[%d]/frequencies/standby-mhz", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index ); snprintf(propname, 256, "/radios/nav[%d]/frequencies/selected-mhz", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index ); snprintf(propname, 256, "/radios/nav[%d]/frequencies/standby-mhz", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index ); snprintf(propname, 256, "/radios/nav[%d]/radials/actual-deg", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index ); snprintf(propname, 256, "/radios/nav[%d]/radials/selected-deg", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/ident", index ); snprintf(propname, 256, "/radios/nav[%d]/ident", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/to-flag", index ); snprintf(propname, 256, "/radios/nav[%d]/to-flag", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/from-flag", index ); snprintf(propname, 256, "/radios/nav[%d]/from-flag", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/in-range", index ); snprintf(propname, 256, "/radios/nav[%d]/in-range", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index ); snprintf(propname, 256, "/radios/nav[%d]/heading-needle-deflection", index);
fgUntie( propname ); fgUntie( propname );
sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index ); snprintf(propname, 256, "/radios/nav[%d]/gs-needle-deflection", index);
fgUntie( propname ); fgUntie( propname );
} }

View file

@ -220,6 +220,11 @@ public:
double get_nav_gs_needle_deflection() const; double get_nav_gs_needle_deflection() const;
inline double get_nav_vol_btn() const { return nav_vol_btn; } inline double get_nav_vol_btn() const { return nav_vol_btn; }
inline bool get_nav_ident_btn() const { return nav_ident_btn; } inline bool get_nav_ident_btn() const { return nav_ident_btn; }
inline const char * get_nav_id() const { return nav_id.c_str(); }
inline int get_nav_id_c1() const { return nav_id.c_str()[0]; }
inline int get_nav_id_c2() const { return nav_id.c_str()[1]; }
inline int get_nav_id_c3() const { return nav_id.c_str()[2]; }
inline int get_nav_id_c4() const { return nav_id.c_str()[3]; }
}; };