Add some bad allocation checks

This commit is contained in:
Markus Gans 2017-08-12 22:55:29 +02:00
parent 2a85f7e977
commit abd501b558
24 changed files with 866 additions and 219 deletions

View File

@ -312,8 +312,17 @@ void FApplication::init()
gpm_ev.x = -1; gpm_ev.x = -1;
#endif #endif
zero_point = new FPoint(0,0); try
event_queue = new eventQueue; {
zero_point = new FPoint(0,0);
event_queue = new eventQueue;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
std::abort();
}
// init arrays with '\0' // init arrays with '\0'
std::fill_n (k_buf, sizeof(k_buf), '\0'); std::fill_n (k_buf, sizeof(k_buf), '\0');
std::fill_n (fifo_buf, fifo_buf_size, '\0'); std::fill_n (fifo_buf, fifo_buf_size, '\0');

View File

@ -253,7 +253,15 @@ void FButton::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -502,10 +510,18 @@ void FButton::draw()
hotkey_offset = 0; hotkey_offset = 0;
space = int(' '); space = int(' ');
if ( isMonochron() || getMaxColor() < 16 ) try
ButtonText = new wchar_t[length+3](); {
else if ( isMonochron() || getMaxColor() < 16 )
ButtonText = new wchar_t[length+1](); ButtonText = new wchar_t[length+3]();
else
ButtonText = new wchar_t[length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
txt = FString(text); txt = FString(text);
src = const_cast<wchar_t*>(txt.wc_str()); src = const_cast<wchar_t*>(txt.wc_str());

View File

@ -206,7 +206,16 @@ void FButtonGroup::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -491,7 +500,17 @@ void FButtonGroup::drawLabel()
txt = " " + text + " "; txt = " " + text + " ";
length = txt.getLength(); length = txt.getLength();
hotkeypos = -1; hotkeypos = -1;
LabelText = new wchar_t[length+1]();
try
{
LabelText = new wchar_t[length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
src = const_cast<wchar_t*>(txt.wc_str()); src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText); dest = const_cast<wchar_t*>(LabelText);

View File

@ -767,11 +767,20 @@ void FDialog::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getTermPos(); const FPoint& g = ev->getTermPos();
const FPoint& p = dialog_menu->termToWidgetPos(g); const FPoint& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton(); int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
dialog_menu->mouse_down = true; try
setClickedWidget(dialog_menu); {
dialog_menu->onMouseMove(_ev); FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
delete _ev; dialog_menu->mouse_down = true;
setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
} }
} }
@ -1058,9 +1067,27 @@ void FDialog::init()
old_focus->redraw(); old_focus->redraw();
} }
accelerator_list = new Accelerators(); try
{
accelerator_list = new Accelerators();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
// Add the dialog menu // Add the dialog menu
dialog_menu = new FMenu ("-", this); try
{
dialog_menu = new FMenu ("-", this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
dialog_menu->setPos (getX(), getY()+1); dialog_menu->setPos (getX(), getY()+1);
dgl_menuitem = dialog_menu->getItem(); dgl_menuitem = dialog_menu->getItem();
@ -1070,7 +1097,16 @@ void FDialog::init()
dgl_menuitem->unsetFocusable(); dgl_menuitem->unsetFocusable();
} }
move_size_item = new FMenuItem (dialog_menu); try
{
move_size_item = new FMenuItem (dialog_menu);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
move_size_item->setText ("&Move/Size"); move_size_item->setText ("&Move/Size");
move_size_item->setStatusbarMessage ("Move or change the size of the window"); move_size_item->setStatusbarMessage ("Move or change the size of the window");
@ -1080,7 +1116,16 @@ void FDialog::init()
F_METHOD_CALLBACK (this, &FDialog::cb_move) F_METHOD_CALLBACK (this, &FDialog::cb_move)
); );
zoom_item = new FMenuItem (dialog_menu); try
{
zoom_item = new FMenuItem (dialog_menu);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
setZoomItem(); setZoomItem();
zoom_item->setDisable(); zoom_item->setDisable();
@ -1090,7 +1135,16 @@ void FDialog::init()
F_METHOD_CALLBACK (this, &FDialog::cb_zoom) F_METHOD_CALLBACK (this, &FDialog::cb_zoom)
); );
close_item = new FMenuItem ("&Close", dialog_menu); try
{
close_item = new FMenuItem ("&Close", dialog_menu);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
close_item->setStatusbarMessage ("Close this window"); close_item->setStatusbarMessage ("Close this window");
close_item->addCallback close_item->addCallback
@ -1421,15 +1475,24 @@ void FDialog::cb_move (FWidget*, data_ptr)
setMoveSizeWidget(this); setMoveSizeWidget(this);
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
drawBorder(); drawBorder();
if ( isMonochron() ) if ( isMonochron() )
setReverse(false); setReverse(false);
save_geometry = getGeometry(); save_geometry = getGeometry();
tooltip = new FToolTip(this);
try
{
tooltip = new FToolTip(this);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
if ( isResizeable() ) if ( isResizeable() )
{ {

View File

@ -375,10 +375,18 @@ const FString FFileDialog::fileOpenChooser ( FWidget* parent
if ( file_filter.isNull() || file_filter.isEmpty() ) if ( file_filter.isNull() || file_filter.isEmpty() )
file_filter = FString("*"); file_filter = FString("*");
fileopen = new FFileDialog ( path try
, file_filter {
, FFileDialog::Open fileopen = new FFileDialog ( path
, parent ); , file_filter
, FFileDialog::Open
, parent );
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return FString();
}
if ( fileopen->exec() == FDialog::Accept ) if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile(); ret = fileopen->getPath() + fileopen->getSelectedFile();
@ -410,10 +418,18 @@ const FString FFileDialog::fileSaveChooser ( FWidget* parent
if ( file_filter.isNull() || file_filter.isEmpty() ) if ( file_filter.isNull() || file_filter.isEmpty() )
file_filter = FString("*"); file_filter = FString("*");
fileopen = new FFileDialog ( path try
, file_filter {
, FFileDialog::Save fileopen = new FFileDialog ( path
, parent ); , file_filter
, FFileDialog::Save
, parent );
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return FString();
}
if ( fileopen->exec() == FDialog::Accept ) if ( fileopen->exec() == FDialog::Accept )
ret = fileopen->getPath() + fileopen->getSelectedFile(); ret = fileopen->getPath() + fileopen->getSelectedFile();
@ -490,29 +506,37 @@ void FFileDialog::init()
else else
FDialog::setText("Open file"); FDialog::setText("Open file");
filename = new FLineEdit(this); try
filename->setLabelText("File&name"); {
filename->setText(filter_pattern); filename = new FLineEdit(this);
filename->setGeometry(11, 1, 28, 1); filename->setLabelText("File&name");
filename->setFocus(); filename->setText(filter_pattern);
filename->setGeometry(11, 1, 28, 1);
filename->setFocus();
filebrowser = new FListBox(this); filebrowser = new FListBox(this);
filebrowser->setGeometry(2, 3, 38, 6); filebrowser->setGeometry(2, 3, 38, 6);
printPath(directory); printPath(directory);
hidden = new FCheckBox("&hidden files", this); hidden = new FCheckBox("&hidden files", this);
hidden->setGeometry(2, 10, 16, 1); hidden->setGeometry(2, 10, 16, 1);
cancel = new FButton("&Cancel", this); cancel = new FButton("&Cancel", this);
cancel->setGeometry(19, 10, 9, 1); cancel->setGeometry(19, 10, 9, 1);
if ( dlg_type == FFileDialog::Save ) if ( dlg_type == FFileDialog::Save )
open = new FButton("&Save",this); open = new FButton("&Save",this);
else else
open = new FButton("&Open",this); open = new FButton("&Open",this);
open->setGeometry(30, 10, 9, 1); open->setGeometry(30, 10, 9, 1);
setGeometry (x, y, getWidth(), getHeight()); setGeometry (x, y, getWidth(), getHeight());
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
filename->addCallback filename->addCallback
( (

View File

@ -158,7 +158,16 @@ void FLabel::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[getWidth()] = '\0'; blank[getWidth()] = '\0';
setPrintPos (1,1); setPrintPos (1,1);
@ -180,9 +189,18 @@ void FLabel::onMouseDown (FMouseEvent* ev)
int b = ev->getButton(); int b = ev->getButton();
const FPoint& tp = ev->getTermPos(); const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp); const FPoint& p = parent->termToWidgetPos(tp);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
} }
return; return;
@ -468,7 +486,17 @@ void FLabel::draw()
while ( y < text_lines && y < uInt(getHeight()) ) while ( y < text_lines && y < uInt(getHeight()) )
{ {
length = multiline_text[y].getLength(); length = multiline_text[y].getLength();
LabelText = new wchar_t[length+1]();
try
{
LabelText = new wchar_t[length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
src = const_cast<wchar_t*>(multiline_text[y].wc_str()); src = const_cast<wchar_t*>(multiline_text[y].wc_str());
dest = const_cast<wchar_t*>(LabelText); dest = const_cast<wchar_t*>(LabelText);
@ -499,7 +527,17 @@ void FLabel::draw()
else else
{ {
length = text.getLength(); length = text.getLength();
LabelText = new wchar_t[length+1]();
try
{
LabelText = new wchar_t[length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
src = const_cast<wchar_t*>(text.wc_str()); src = const_cast<wchar_t*>(text.wc_str());
dest = const_cast<wchar_t*>(LabelText); dest = const_cast<wchar_t*>(LabelText);
hotkeypos = getHotkeyPos (src, dest, length); hotkeypos = getHotkeyPos (src, dest, length);

View File

@ -193,7 +193,16 @@ void FLineEdit::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';

View File

@ -243,7 +243,16 @@ void FListBox::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset (blank, ' ', uLong(size)); std::memset (blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -369,7 +378,16 @@ void FListBox::clear()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset (blank, ' ', uLong(size)); std::memset (blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -1225,15 +1243,23 @@ void FListBox::init()
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this); try
vbar->setMinimum(0); {
vbar->setValue(0); vbar = new FScrollbar(fc::vertical, this);
vbar->hide(); vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
setGeometry (1, 1, 5, 4, false); // initialize geometry values setGeometry (1, 1, 5, 4, false); // initialize geometry values

View File

@ -282,10 +282,18 @@ void FListView::insert ( const std::vector<FString>& cols
, data_ptr d , data_ptr d
, FListView* parent ) , FListView* parent )
{ {
if ( parent == 0 ) try
new FListViewItem (cols, d, this); {
else if ( parent == 0 )
new FListViewItem (cols, d, parent); new FListViewItem (cols, d, this);
else
new FListViewItem (cols, d, parent);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -874,15 +882,23 @@ void FListView::init()
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this); try
vbar->setMinimum(0); {
vbar->setValue(0); vbar = new FScrollbar(fc::vertical, this);
vbar->hide(); vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
setGeometry (1, 1, 5, 4, false); // initialize geometry values setGeometry (1, 1, 5, 4, false); // initialize geometry values

View File

@ -34,7 +34,16 @@ FMenu::FMenu (const FString& txt, FWidget* parent)
, mouse_down(false) , mouse_down(false)
, has_checkable_items(false) , has_checkable_items(false)
{ {
item = new FMenuItem(txt, parent); try
{
item = new FMenuItem(txt, parent);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
init(parent); init(parent);
} }
@ -582,11 +591,20 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
const FPoint& p = open_sub_menu->termToWidgetPos(t); const FPoint& p = open_sub_menu->termToWidgetPos(t);
int b = ev->getButton(); int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
open_sub_menu->mouse_down = true; try
setClickedWidget(open_sub_menu); {
open_sub_menu->onMouseMove(_ev); FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
delete _ev; open_sub_menu->mouse_down = true;
setClickedWidget(open_sub_menu);
open_sub_menu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
return; return;
} }
else if ( ! mouse_over_menu && mouse_over_supermenu ) else if ( ! mouse_over_menu && mouse_over_supermenu )
@ -595,11 +613,20 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
const FPoint& p = smenu->termToWidgetPos(t); const FPoint& p = smenu->termToWidgetPos(t);
int b = ev->getButton(); int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
smenu->mouse_down = true; try
setClickedWidget(smenu); {
smenu->onMouseMove(_ev); FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
delete _ev; smenu->mouse_down = true;
setClickedWidget(smenu);
smenu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
return; return;
} }
else if ( mouse_over_menubar ) else if ( mouse_over_menubar )
@ -609,12 +636,21 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
const FPoint& p = menubar->termToWidgetPos(t); const FPoint& p = menubar->termToWidgetPos(t);
int b = ev->getButton(); int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
setClickedWidget(menubar); try
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar); {
mbar->mouse_down = true; FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
mbar->onMouseMove(_ev); setClickedWidget(menubar);
delete _ev; FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar);
mbar->mouse_down = true;
mbar->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
return; return;
} }
else if ( ! hasSelectedItem() && mouse_over_menu ) else if ( ! hasSelectedItem() && mouse_over_menu )
@ -1307,7 +1343,17 @@ void FMenu::drawItems()
print (' '); print (' ');
txt = (*iter)->getText(); txt = (*iter)->getText();
txt_length = uInt(txt.getLength()); txt_length = uInt(txt.getLength());
item_text = new wchar_t[txt_length+1]();
try
{
item_text = new wchar_t[txt_length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
src = const_cast<wchar_t*>(txt.wc_str()); src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(item_text); dest = const_cast<wchar_t*>(item_text);
to_char = int(txt_length); to_char = int(txt_length);

View File

@ -43,7 +43,16 @@ void FMenuBar::hide()
if ( screenWidth < 0 ) if ( screenWidth < 0 )
return; return;
blank = new char[screenWidth+1]; try
{
blank = new char[screenWidth+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(screenWidth)); std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0'; blank[screenWidth] = '\0';
setPrintPos (1,1); setPrintPos (1,1);
@ -408,11 +417,19 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos(); const FPoint& t = ev->getTermPos();
const FPoint& p = menu->termToWidgetPos(t); const FPoint& p = menu->termToWidgetPos(t);
int b = ev->getButton(); int b = ev->getButton();
_ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
menu->mouse_down = true; try
setClickedWidget(menu); {
menu->onMouseMove(_ev); _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
delete _ev; menu->mouse_down = true;
setClickedWidget(menu);
menu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
} }
@ -799,7 +816,17 @@ void FMenuBar::drawItems()
txt = (*iter)->getText(); txt = (*iter)->getText();
txt_length = uInt(txt.getLength()); txt_length = uInt(txt.getLength());
item_text = new wchar_t[txt_length+1]();
try
{
item_text = new wchar_t[txt_length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
src = const_cast<wchar_t*>(txt.wc_str()); src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(item_text); dest = const_cast<wchar_t*>(item_text);

View File

@ -333,9 +333,17 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( smenu ) if ( smenu )
{ {
const FPoint& p2 = smenu->termToWidgetPos(t); const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
smenu->onMouseDoubleClick(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
smenu->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -346,9 +354,17 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( mbar ) if ( mbar )
{ {
const FPoint& p2 = mbar->termToWidgetPos(t); const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
mbar->onMouseDoubleClick(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
mbar->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -359,9 +375,17 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( dgl ) if ( dgl )
{ {
const FPoint& p2 = dgl->termToWidgetPos(t); const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
dgl->onMouseDoubleClick(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
dgl->onMouseDoubleClick(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
} }
@ -382,9 +406,17 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( smenu ) if ( smenu )
{ {
const FPoint& p2 = smenu->termToWidgetPos(t); const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
smenu->onMouseDown(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
smenu->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -395,9 +427,17 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( mbar ) if ( mbar )
{ {
const FPoint& p2 = mbar->termToWidgetPos(t); const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
mbar->onMouseDown(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
mbar->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -408,9 +448,17 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( dgl ) if ( dgl )
{ {
const FPoint& p2 = dgl->termToWidgetPos(t); const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
dgl->onMouseDown(_ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
dgl->onMouseDown(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
} }
@ -734,11 +782,20 @@ void FMenuItem::createDialogList (FMenu* winmenu)
if ( win ) if ( win )
{ {
FMenuItem* win_item;
int n = int(std::distance(begin, iter)); int n = int(std::distance(begin, iter));
// get the dialog title // get the dialog title
const FString& name = win->getText(); const FString& name = win->getText();
// create a new dialog list item
FMenuItem* win_item = new FMenuItem (name, winmenu); try
{
// create a new dialog list item
win_item = new FMenuItem (name, winmenu);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
if ( n < 9 ) if ( n < 9 )
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9 win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9

View File

@ -170,9 +170,20 @@ int FMessageBox::info ( FWidget* parent
, int button2 ) , int button2 )
{ {
int reply; int reply;
FMessageBox* mbox = new FMessageBox ( caption, message FMessageBox* mbox;
, button0, button1, button2
, parent ); try
{
mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return FDialog::Reject;
}
reply = mbox->exec(); reply = mbox->exec();
delete mbox; delete mbox;
return reply; return reply;
@ -187,10 +198,21 @@ int FMessageBox::info ( FWidget* parent
, int button2 ) , int button2 )
{ {
int reply; int reply;
FMessageBox* mbox = new FMessageBox ( caption FMessageBox* mbox;
, FString().setNumber(num)
, button0, button1, button2 try
, parent ); {
mbox = new FMessageBox ( caption
, FString().setNumber(num)
, button0, button1, button2
, parent );
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return FDialog::Reject;
}
reply = mbox->exec(); reply = mbox->exec();
delete mbox; delete mbox;
return reply; return reply;
@ -205,9 +227,20 @@ int FMessageBox::error ( FWidget* parent
{ {
int reply; int reply;
const FString& caption = "Error message"; const FString& caption = "Error message";
FMessageBox* mbox = new FMessageBox ( caption, message FMessageBox* mbox;
, button0, button1, button2
, parent ); try
{
mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return FDialog::Reject;
}
mbox->beep(); mbox->beep();
mbox->setHeadline("Warning:"); mbox->setHeadline("Warning:");
mbox->setCenterText(); mbox->setCenterText();
@ -278,29 +311,37 @@ void FMessageBox::init (int button0, int button1, int button2)
button_digit[1] = button1; button_digit[1] = button1;
button_digit[2] = button2; button_digit[2] = button2;
button[0] = new FButton (this); try
button[0]->setText(button_text[button0]);
button[0]->setPos(3, getHeight()-4, false);
button[0]->setWidth(1, false);
button[0]->setHeight(1, false);
button[0]->setFocus();
if ( button1 > 0 )
{ {
button[1] = new FButton(this); button[0] = new FButton (this);
button[1]->setText(button_text[button1]); button[0]->setText(button_text[button0]);
button[1]->setPos(17, getHeight()-4, false); button[0]->setPos(3, getHeight()-4, false);
button[1]->setWidth(0, false); button[0]->setWidth(1, false);
button[1]->setHeight(1, false); button[0]->setHeight(1, false);
button[0]->setFocus();
if ( button1 > 0 )
{
button[1] = new FButton(this);
button[1]->setText(button_text[button1]);
button[1]->setPos(17, getHeight()-4, false);
button[1]->setWidth(0, false);
button[1]->setHeight(1, false);
}
if ( button2 > 0 )
{
button[2] = new FButton(this);
button[2]->setText(button_text[button2]);
button[2]->setPos(32, getHeight()-4, false);
button[2]->setWidth(0, false);
button[2]->setHeight(1, false);
}
} }
catch (const std::bad_alloc& ex)
if ( button2 > 0 )
{ {
button[2] = new FButton(this); std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
button[2]->setText(button_text[button2]); return;
button[2]->setPos(32, getHeight()-4, false);
button[2]->setWidth(0, false);
button[2]->setHeight(1, false);
} }
resizeButtons(); resizeButtons();

View File

@ -31,10 +31,30 @@ FObject::FObject (FObject* parent)
timer_modify_lock = false; timer_modify_lock = false;
if ( ! timer_list ) if ( ! timer_list )
timer_list = new TimerList(); {
try
{
timer_list = new TimerList();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
}
if ( ! fc::empty_string ) if ( ! fc::empty_string )
fc::empty_string = new FString(""); {
try
{
fc::empty_string = new FString("");
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
}
} }
else else
has_parent = true; has_parent = true;
@ -176,7 +196,17 @@ int FObject::addTimer (int interval)
timer_modify_lock = true; timer_modify_lock = true;
if ( ! timer_list ) if ( ! timer_list )
timer_list = new TimerList(); {
try
{
timer_list = new TimerList();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return -1;
}
}
// find an unused timer id // find an unused timer id
if ( ! timer_list->empty() ) if ( ! timer_list->empty() )

View File

@ -102,7 +102,16 @@ void FProgressbar::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';

View File

@ -762,15 +762,23 @@ void FScrollView::init (FWidget* parent)
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this); try
vbar->setMinimum(0); {
vbar->setValue(0); vbar = new FScrollbar(fc::vertical, this);
vbar->hide(); vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
vbar->addCallback vbar->addCallback
( (

View File

@ -184,7 +184,16 @@ void FStatusBar::hide()
if ( screenWidth < 0 ) if ( screenWidth < 0 )
return; return;
blank = new char[screenWidth+1]; try
{
blank = new char[screenWidth+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(screenWidth)); std::memset(blank, ' ', uLong(screenWidth));
blank[screenWidth] = '\0'; blank[screenWidth] = '\0';
setPrintPos (1, 1); setPrintPos (1, 1);

View File

@ -528,7 +528,16 @@ FString& FString::sprintf (const char* format, ...)
if ( len >= int(sizeof(buf)) ) if ( len >= int(sizeof(buf)) )
{ {
buffer = new char[len+1](); try
{
buffer = new char[len+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return (*this);
}
va_start (args, format); va_start (args, format);
vsnprintf (buffer, uLong(len+1), format, args); vsnprintf (buffer, uLong(len+1), format, args);
va_end (args); va_end (args);
@ -2216,8 +2225,16 @@ inline void FString::initLength (uInt len)
length = len; length = len;
bufsize = FWDBUFFER + len + 1; bufsize = FWDBUFFER + len + 1;
string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize); try
{
string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -900,13 +900,24 @@ const FString* FTerm::getXTermFont()
{ {
if ( std::scanf("\033]50;%[^\n]s", temp) == 1 ) if ( std::scanf("\033]50;%[^\n]s", temp) == 1 )
{ {
FString* xtermfont;
std::size_t n = std::strlen(temp); std::size_t n = std::strlen(temp);
// BEL + '\0' = string terminator // BEL + '\0' = string terminator
if ( n >= 5 && temp[n-1] == BEL[0] && temp[n] == '\0' ) if ( n >= 5 && temp[n-1] == BEL[0] && temp[n] == '\0' )
temp[n-1] = '\0'; temp[n-1] = '\0';
return new FString(temp); try
{
xtermfont = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return 0;
}
return xtermfont;
} }
} }
} }
@ -942,11 +953,24 @@ const FString* FTerm::getXTermTitle()
// Esc + \ = OSC string terminator // Esc + \ = OSC string terminator
if ( n >= 2 && temp[n-2] == ESC[0] && temp[n-1] == '\\' ) if ( n >= 2 && temp[n-2] == ESC[0] && temp[n-1] == '\\' )
{ {
FString* xtermtitle;
if ( n < 4 ) if ( n < 4 )
return 0; return 0;
temp[n-2] = '\0'; temp[n-2] = '\0';
return new FString(temp);
try
{
xtermtitle = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return 0;
}
return xtermtitle;
} }
} }
} }
@ -2180,7 +2204,15 @@ int FTerm::getScreenFont()
font.height = 32; font.height = 32;
font.charcount = 512; font.charcount = 512;
// initialize with 0 // initialize with 0
font.data = new uChar[data_size](); try
{
font.data = new uChar[data_size]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return -1;
}
// font operation // font operation
ret = ioctl (fd_tty, KDFONTOP, &font); ret = ioctl (fd_tty, KDFONTOP, &font);
@ -2619,9 +2651,17 @@ char* FTerm::parseAnswerbackMsg (char*& current_termtype)
char* new_termtype = current_termtype; char* new_termtype = current_termtype;
// send ENQ and read the answerback message // send ENQ and read the answerback message
answer_back = new FString(getAnswerbackMsg()); try
{
answer_back = new FString(getAnswerbackMsg());
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return 0;
}
if ( answer_back && *answer_back == FString("PuTTY") ) if ( *answer_back == FString("PuTTY") )
{ {
putty_terminal = true; putty_terminal = true;
@ -2662,10 +2702,10 @@ char* FTerm::parseSecDA (char*& current_termtype)
// secondary device attributes (SEC_DA) <- decTerminalID string // secondary device attributes (SEC_DA) <- decTerminalID string
sec_da = new FString(getSecDA()); sec_da = new FString(getSecDA());
} }
catch (const std::bad_alloc& ex)
catch (const std::bad_alloc&)
{ {
return new_termtype; std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return new_termtype;
} }
if ( sec_da->getLength() > 5 ) if ( sec_da->getLength() > 5 )
@ -3579,14 +3619,22 @@ void FTerm::init()
char* new_termtype = 0; char* new_termtype = 0;
term_initialized = true; term_initialized = true;
init_term_object = this; init_term_object = this;
fd_tty = -1; fd_tty = -1;
opti_move = new FOptiMove();
opti_attr = new FOptiAttr();
term = new FRect(0,0,0,0);
mouse = new FPoint(0,0);
vt100_alt_char = new std::map<uChar,uChar>; try
encoding_set = new std::map<std::string,fc::encoding>; {
opti_move = new FOptiMove();
opti_attr = new FOptiAttr();
term = new FRect(0,0,0,0);
mouse = new FPoint(0,0);
vt100_alt_char = new std::map<uChar,uChar>;
encoding_set = new std::map<std::string,fc::encoding>;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
std::abort();
}
// Define the encoding set // Define the encoding set
(*encoding_set)["UTF8"] = fc::UTF8; (*encoding_set)["UTF8"] = fc::UTF8;

View File

@ -52,7 +52,16 @@ int FTermBuffer::writef (const char* format, ...)
if ( len >= int(sizeof(buf)) ) if ( len >= int(sizeof(buf)) )
{ {
buffer = new char[len+1](); try
{
buffer = new char[len+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return -1;
}
va_start (args, format); va_start (args, format);
vsnprintf (buffer, uLong(len+1), format, args); vsnprintf (buffer, uLong(len+1), format, args);
va_end (args); va_end (args);

View File

@ -150,7 +150,16 @@ void FTextView::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -276,7 +285,16 @@ void FTextView::clear()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
@ -419,9 +437,17 @@ void FTextView::onMouseDown (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos(); const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp); const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -441,9 +467,17 @@ void FTextView::onMouseUp (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos(); const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp); const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p, tp, b);
FApplication::sendEvent (parent, _ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
if ( vbar->isVisible() ) if ( vbar->isVisible() )
@ -469,9 +503,17 @@ void FTextView::onMouseMove (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos(); const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp); const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus(); parent->setFocus();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, tp, b);
FApplication::sendEvent (parent, _ev); try
delete _ev; {
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
} }
@ -604,15 +646,23 @@ void FTextView::init()
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this); try
vbar->setMinimum(0); {
vbar->setValue(0); vbar = new FScrollbar(fc::vertical, this);
vbar->hide(); vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
vbar->addCallback vbar->addCallback
( (

View File

@ -217,7 +217,16 @@ void FToggleButton::hide()
if ( size < 0 ) if ( size < 0 )
return; return;
blank = new char[size+1]; try
{
blank = new char[size+1];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
std::memset(blank, ' ', uLong(size)); std::memset(blank, ' ', uLong(size));
blank[size] = '\0'; blank[size] = '\0';
setPrintPos (1, 1); setPrintPos (1, 1);
@ -485,7 +494,16 @@ void FToggleButton::drawLabel()
length = text.getLength(); length = text.getLength();
hotkeypos = -1; hotkeypos = -1;
LabelText = new wchar_t[length+1](); try
{
LabelText = new wchar_t[length+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
txt = text; txt = text;
src = const_cast<wchar_t*>(txt.wc_str()); src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText); dest = const_cast<wchar_t*>(LabelText);

View File

@ -317,7 +317,15 @@ int FVTerm::printf (const char* format, ...)
if ( len >= int(sizeof(buf)) ) if ( len >= int(sizeof(buf)) )
{ {
buffer = new char[len+1](); try
{
buffer = new char[len+1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return -1;
}
va_start (args, format); va_start (args, format);
vsnprintf (buffer, uLong(len+1), format, args); vsnprintf (buffer, uLong(len+1), format, args);
va_end (args); va_end (args);
@ -903,7 +911,16 @@ void FVTerm::createArea ( int offset_left, int offset_top
{ {
// initialize virtual window // initialize virtual window
area = new term_area; try
{
area = new term_area;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
area->widget = static_cast<FWidget*>(this); area->widget = static_cast<FWidget*>(this);
resizeArea (offset_left, offset_top, width, height, rsw, bsh, area); resizeArea (offset_left, offset_top, width, height, rsw, bsh, area);
} }
@ -966,15 +983,31 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
if ( area->text != 0 ) if ( area->text != 0 )
delete[] area->text; delete[] area->text;
area->changes = new line_changes[height + bsh]; try
area->text = new char_data[area_size]; {
area->changes = new line_changes[height + bsh];
area->text = new char_data[area_size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
} }
else if ( area->width + area->right_shadow != width + rsw ) else if ( area->width + area->right_shadow != width + rsw )
{ {
if ( area->text != 0 ) if ( area->text != 0 )
delete[] area->text; delete[] area->text;
area->text = new char_data[area_size]; try
{
area->text = new char_data[area_size];
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
} }
else else
return; return;
@ -2221,8 +2254,17 @@ void FVTerm::init()
init_object = this; init_object = this;
vterm = 0; vterm = 0;
vdesktop = 0; vdesktop = 0;
term_pos = new FPoint(-1,-1);
output_buffer = new std::queue<int>; try
{
term_pos = new FPoint(-1,-1);
output_buffer = new std::queue<int>;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
std::abort();
}
// Preset to false // Preset to false
hidden_cursor = \ hidden_cursor = \

View File

@ -2276,10 +2276,19 @@ void FWidget::onClose (FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::init() void FWidget::init()
{ {
window_list = new widgetList(); try
dialog_list = new widgetList(); {
always_on_top_list = new widgetList(); // Initialize widget lists
close_widget = new widgetList(); window_list = new widgetList();
dialog_list = new widgetList();
always_on_top_list = new widgetList();
close_widget = new widgetList();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
char* cursor_off_str = disableCursor(); char* cursor_off_str = disableCursor();
@ -2290,7 +2299,7 @@ void FWidget::init()
visible_cursor = ! hideable; visible_cursor = ! hideable;
// determine width and height of the terminal // Determine width and height of the terminal
detectTermSize(); detectTermSize();
wsize.setRect(1, 1, getColumnNumber(), getLineNumber()); wsize.setRect(1, 1, getColumnNumber(), getLineNumber());
adjust_wsize = wsize; adjust_wsize = wsize;
@ -2309,7 +2318,14 @@ void FWidget::init()
background_color = wc.term_bg; background_color = wc.term_bg;
init_desktop = false; init_desktop = false;
accelerator_list = new Accelerators(); try
{
accelerator_list = new Accelerators();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------