better use strncpy() than strncat() with uninitialized buffer

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2002-08-13 19:40:41 +00:00
parent 48d011c896
commit 982f23fd00
2 changed files with 14 additions and 10 deletions

View File

@ -1068,10 +1068,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
#endif // USE_MENU_BITMAPS #endif // USE_MENU_BITMAPS
else // a normal item else // a normal item
{ {
/* text has "_" instead of "&" after mitem->SetText() */ // text has "_" instead of "&" after mitem->SetText() so don't use it
wxString text( mitem->GetText() ); wxString text( mitem->GetText() );
/* local buffer in multibyte form */ // buffer containing the menu text in multibyte form
char buf[200]; char buf[200];
strcpy( buf, "/" ); strcpy( buf, "/" );
strncat( buf, wxGTK_CONV(text), WXSIZEOF(buf) - 2 ); strncat( buf, wxGTK_CONV(text), WXSIZEOF(buf) - 2 );
@ -1083,7 +1083,6 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
entry.callback_action = 0; entry.callback_action = 0;
wxString pathRadio; wxString pathRadio;
char buf2[200];
const char *item_type; const char *item_type;
switch ( mitem->GetKind() ) switch ( mitem->GetKind() )
{ {
@ -1103,7 +1102,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
pathRadio = m_pathLastRadio; pathRadio = m_pathLastRadio;
pathRadio.Replace(wxT("_"), wxT("")); pathRadio.Replace(wxT("_"), wxT(""));
pathRadio.Prepend(wxT("<main>/")); pathRadio.Prepend(wxT("<main>/"));
strncat( buf2, wxGTK_CONV(pathRadio), WXSIZEOF(buf2) - 2 );
char buf2[200];
strncpy(buf2, wxGTK_CONV(pathRadio), WXSIZEOF(buf2));
buf2[WXSIZEOF(buf2) - 1] = '\0'; buf2[WXSIZEOF(buf2) - 1] = '\0';
item_type = buf2; item_type = buf2;
} }
@ -1128,9 +1129,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
// due to an apparent bug in GTK+, we have to use a static buffer here - // due to an apparent bug in GTK+, we have to use a static buffer here -
// otherwise GTK+ 1.2.2 manages to override the memory we pass to it // otherwise GTK+ 1.2.2 manages to override the memory we pass to it
// somehow! (VZ) // somehow! (VZ)
static char s_accel[50]; // must be big enough char s_accel[50]; // should be big enough, we check for overruns
wxString tmp( GetHotKey(*mitem) ); wxString tmp( GetHotKey(*mitem) );
strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel)); strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel));
s_accel[WXSIZEOF(s_accel) - 1] = '\0';
entry.accelerator = s_accel; entry.accelerator = s_accel;
#else // !wxUSE_ACCEL #else // !wxUSE_ACCEL
entry.accelerator = (char*) NULL; entry.accelerator = (char*) NULL;

View File

@ -1068,10 +1068,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
#endif // USE_MENU_BITMAPS #endif // USE_MENU_BITMAPS
else // a normal item else // a normal item
{ {
/* text has "_" instead of "&" after mitem->SetText() */ // text has "_" instead of "&" after mitem->SetText() so don't use it
wxString text( mitem->GetText() ); wxString text( mitem->GetText() );
/* local buffer in multibyte form */ // buffer containing the menu text in multibyte form
char buf[200]; char buf[200];
strcpy( buf, "/" ); strcpy( buf, "/" );
strncat( buf, wxGTK_CONV(text), WXSIZEOF(buf) - 2 ); strncat( buf, wxGTK_CONV(text), WXSIZEOF(buf) - 2 );
@ -1083,7 +1083,6 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
entry.callback_action = 0; entry.callback_action = 0;
wxString pathRadio; wxString pathRadio;
char buf2[200];
const char *item_type; const char *item_type;
switch ( mitem->GetKind() ) switch ( mitem->GetKind() )
{ {
@ -1103,7 +1102,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
pathRadio = m_pathLastRadio; pathRadio = m_pathLastRadio;
pathRadio.Replace(wxT("_"), wxT("")); pathRadio.Replace(wxT("_"), wxT(""));
pathRadio.Prepend(wxT("<main>/")); pathRadio.Prepend(wxT("<main>/"));
strncat( buf2, wxGTK_CONV(pathRadio), WXSIZEOF(buf2) - 2 );
char buf2[200];
strncpy(buf2, wxGTK_CONV(pathRadio), WXSIZEOF(buf2));
buf2[WXSIZEOF(buf2) - 1] = '\0'; buf2[WXSIZEOF(buf2) - 1] = '\0';
item_type = buf2; item_type = buf2;
} }
@ -1128,9 +1129,10 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem)
// due to an apparent bug in GTK+, we have to use a static buffer here - // due to an apparent bug in GTK+, we have to use a static buffer here -
// otherwise GTK+ 1.2.2 manages to override the memory we pass to it // otherwise GTK+ 1.2.2 manages to override the memory we pass to it
// somehow! (VZ) // somehow! (VZ)
static char s_accel[50]; // must be big enough char s_accel[50]; // should be big enough, we check for overruns
wxString tmp( GetHotKey(*mitem) ); wxString tmp( GetHotKey(*mitem) );
strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel)); strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel));
s_accel[WXSIZEOF(s_accel) - 1] = '\0';
entry.accelerator = s_accel; entry.accelerator = s_accel;
#else // !wxUSE_ACCEL #else // !wxUSE_ACCEL
entry.accelerator = (char*) NULL; entry.accelerator = (char*) NULL;