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;
#endif
zero_point = new FPoint(0,0);
event_queue = new eventQueue;
try
{
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'
std::fill_n (k_buf, sizeof(k_buf), '\0');
std::fill_n (fifo_buf, fifo_buf_size, '\0');

View File

@ -253,7 +253,15 @@ void FButton::hide()
if ( size < 0 )
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));
blank[size] = '\0';
@ -502,10 +510,18 @@ void FButton::draw()
hotkey_offset = 0;
space = int(' ');
if ( isMonochron() || getMaxColor() < 16 )
ButtonText = new wchar_t[length+3]();
else
ButtonText = new wchar_t[length+1]();
try
{
if ( isMonochron() || getMaxColor() < 16 )
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);
src = const_cast<wchar_t*>(txt.wc_str());

View File

@ -206,7 +206,16 @@ void FButtonGroup::hide()
if ( size < 0 )
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));
blank[size] = '\0';
@ -491,7 +500,17 @@ void FButtonGroup::drawLabel()
txt = " " + text + " ";
length = txt.getLength();
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());
dest = const_cast<wchar_t*>(LabelText);

View File

@ -767,11 +767,20 @@ void FDialog::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getTermPos();
const FPoint& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
dialog_menu->mouse_down = true;
setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev);
delete _ev;
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
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();
}
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
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);
dgl_menuitem = dialog_menu->getItem();
@ -1070,7 +1097,16 @@ void FDialog::init()
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->setStatusbarMessage ("Move or change the size of the window");
@ -1080,7 +1116,16 @@ void FDialog::init()
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();
zoom_item->setDisable();
@ -1090,7 +1135,16 @@ void FDialog::init()
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->addCallback
@ -1421,15 +1475,24 @@ void FDialog::cb_move (FWidget*, data_ptr)
setMoveSizeWidget(this);
if ( isMonochron() )
setReverse(true);
setReverse(true);
drawBorder();
if ( isMonochron() )
setReverse(false);
setReverse(false);
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() )
{

View File

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

View File

@ -158,7 +158,16 @@ void FLabel::hide()
if ( size < 0 )
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));
blank[getWidth()] = '\0';
setPrintPos (1,1);
@ -180,9 +189,18 @@ void FLabel::onMouseDown (FMouseEvent* ev)
int b = ev->getButton();
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev);
delete _ev;
try
{
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;
@ -468,7 +486,17 @@ void FLabel::draw()
while ( y < text_lines && y < uInt(getHeight()) )
{
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());
dest = const_cast<wchar_t*>(LabelText);
@ -499,7 +527,17 @@ void FLabel::draw()
else
{
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());
dest = const_cast<wchar_t*>(LabelText);
hotkeypos = getHotkeyPos (src, dest, length);

View File

@ -193,7 +193,16 @@ void FLineEdit::hide()
if ( size < 0 )
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));
blank[size] = '\0';

View File

@ -243,7 +243,16 @@ void FListBox::hide()
if ( size < 0 )
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));
blank[size] = '\0';
@ -369,7 +378,16 @@ void FListBox::clear()
if ( size < 0 )
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));
blank[size] = '\0';
@ -1225,15 +1243,23 @@ void FListBox::init()
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
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

View File

@ -282,10 +282,18 @@ void FListView::insert ( const std::vector<FString>& cols
, data_ptr d
, FListView* parent )
{
if ( parent == 0 )
new FListViewItem (cols, d, this);
else
new FListViewItem (cols, d, parent);
try
{
if ( parent == 0 )
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);
setBackgroundColor (wc.dialog_bg);
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
hbar = new FScrollbar(fc::horizontal, this);
hbar->setMinimum(0);
hbar->setValue(0);
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

View File

@ -34,7 +34,16 @@ FMenu::FMenu (const FString& txt, FWidget* parent)
, mouse_down(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);
}
@ -582,11 +591,20 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos();
const FPoint& p = open_sub_menu->termToWidgetPos(t);
int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
open_sub_menu->mouse_down = true;
setClickedWidget(open_sub_menu);
open_sub_menu->onMouseMove(_ev);
delete _ev;
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
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;
}
else if ( ! mouse_over_menu && mouse_over_supermenu )
@ -595,11 +613,20 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos();
const FPoint& p = smenu->termToWidgetPos(t);
int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
smenu->mouse_down = true;
setClickedWidget(smenu);
smenu->onMouseMove(_ev);
delete _ev;
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
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;
}
else if ( mouse_over_menubar )
@ -609,12 +636,21 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos();
const FPoint& p = menubar->termToWidgetPos(t);
int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
setClickedWidget(menubar);
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar);
mbar->mouse_down = true;
mbar->onMouseMove(_ev);
delete _ev;
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
setClickedWidget(menubar);
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;
}
else if ( ! hasSelectedItem() && mouse_over_menu )
@ -1307,7 +1343,17 @@ void FMenu::drawItems()
print (' ');
txt = (*iter)->getText();
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());
dest = const_cast<wchar_t*>(item_text);
to_char = int(txt_length);

View File

@ -43,7 +43,16 @@ void FMenuBar::hide()
if ( screenWidth < 0 )
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));
blank[screenWidth] = '\0';
setPrintPos (1,1);
@ -408,11 +417,19 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos();
const FPoint& p = menu->termToWidgetPos(t);
int b = ev->getButton();
_ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
menu->mouse_down = true;
setClickedWidget(menu);
menu->onMouseMove(_ev);
delete _ev;
try
{
_ev = new FMouseEvent (fc::MouseMove_Event, p, t, b);
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_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());
dest = const_cast<wchar_t*>(item_text);

View File

@ -333,9 +333,17 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
smenu->onMouseDoubleClick(_ev);
delete _ev;
try
{
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 )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
mbar->onMouseDoubleClick(_ev);
delete _ev;
try
{
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 )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b);
dgl->onMouseDoubleClick(_ev);
delete _ev;
try
{
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 )
{
const FPoint& p2 = smenu->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
smenu->onMouseDown(_ev);
delete _ev;
try
{
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 )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
mbar->onMouseDown(_ev);
delete _ev;
try
{
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 )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b);
dgl->onMouseDown(_ev);
delete _ev;
try
{
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 )
{
FMenuItem* win_item;
int n = int(std::distance(begin, iter));
// get the dialog title
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 )
win_item->addAccelerator (fc::Fmkey_1 + n); // Meta + 1..9

View File

@ -170,9 +170,20 @@ int FMessageBox::info ( FWidget* parent
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
FMessageBox* mbox;
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();
delete mbox;
return reply;
@ -187,10 +198,21 @@ int FMessageBox::info ( FWidget* parent
, int button2 )
{
int reply;
FMessageBox* mbox = new FMessageBox ( caption
, FString().setNumber(num)
, button0, button1, button2
, parent );
FMessageBox* mbox;
try
{
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();
delete mbox;
return reply;
@ -205,9 +227,20 @@ int FMessageBox::error ( FWidget* parent
{
int reply;
const FString& caption = "Error message";
FMessageBox* mbox = new FMessageBox ( caption, message
, button0, button1, button2
, parent );
FMessageBox* mbox;
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->setHeadline("Warning:");
mbox->setCenterText();
@ -278,29 +311,37 @@ void FMessageBox::init (int button0, int button1, int button2)
button_digit[1] = button1;
button_digit[2] = button2;
button[0] = new FButton (this);
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 )
try
{
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);
button[0] = new FButton (this);
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[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);
}
}
if ( button2 > 0 )
catch (const std::bad_alloc& ex)
{
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);
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
resizeButtons();

View File

@ -27,14 +27,34 @@ FObject::FObject (FObject* parent)
if ( parent == 0 )
{
timer_modify_lock = false;
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 )
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
has_parent = true;
@ -176,7 +196,17 @@ int FObject::addTimer (int interval)
timer_modify_lock = true;
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
if ( ! timer_list->empty() )

View File

@ -102,7 +102,16 @@ void FProgressbar::hide()
if ( size < 0 )
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));
blank[size] = '\0';

View File

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

View File

@ -184,7 +184,16 @@ void FStatusBar::hide()
if ( screenWidth < 0 )
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));
blank[screenWidth] = '\0';
setPrintPos (1, 1);

View File

@ -528,7 +528,16 @@ FString& FString::sprintf (const char* format, ...)
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);
vsnprintf (buffer, uLong(len+1), format, args);
va_end (args);
@ -2216,8 +2225,16 @@ inline void FString::initLength (uInt len)
length = len;
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 )
{
FString* xtermfont;
std::size_t n = std::strlen(temp);
// BEL + '\0' = string terminator
if ( n >= 5 && temp[n-1] == BEL[0] && temp[n] == '\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
if ( n >= 2 && temp[n-2] == ESC[0] && temp[n-1] == '\\' )
{
FString* xtermtitle;
if ( n < 4 )
return 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.charcount = 512;
// 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
ret = ioctl (fd_tty, KDFONTOP, &font);
@ -2619,9 +2651,17 @@ char* FTerm::parseAnswerbackMsg (char*& current_termtype)
char* new_termtype = current_termtype;
// 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;
@ -2662,10 +2702,10 @@ char* FTerm::parseSecDA (char*& current_termtype)
// secondary device attributes (SEC_DA) <- decTerminalID string
sec_da = new FString(getSecDA());
}
catch (const std::bad_alloc&)
catch (const std::bad_alloc& ex)
{
return new_termtype;
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return new_termtype;
}
if ( sec_da->getLength() > 5 )
@ -3579,14 +3619,22 @@ void FTerm::init()
char* new_termtype = 0;
term_initialized = true;
init_term_object = this;
fd_tty = -1;
opti_move = new FOptiMove();
opti_attr = new FOptiAttr();
term = new FRect(0,0,0,0);
mouse = new FPoint(0,0);
fd_tty = -1;
vt100_alt_char = new std::map<uChar,uChar>;
encoding_set = new std::map<std::string,fc::encoding>;
try
{
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
(*encoding_set)["UTF8"] = fc::UTF8;

View File

@ -52,7 +52,16 @@ int FTermBuffer::writef (const char* format, ...)
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);
vsnprintf (buffer, uLong(len+1), format, args);
va_end (args);

View File

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

View File

@ -217,7 +217,16 @@ void FToggleButton::hide()
if ( size < 0 )
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));
blank[size] = '\0';
setPrintPos (1, 1);
@ -485,7 +494,16 @@ void FToggleButton::drawLabel()
length = text.getLength();
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;
src = const_cast<wchar_t*>(txt.wc_str());
dest = const_cast<wchar_t*>(LabelText);

View File

@ -317,7 +317,15 @@ int FVTerm::printf (const char* format, ...)
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);
vsnprintf (buffer, uLong(len+1), format, args);
va_end (args);
@ -903,7 +911,16 @@ void FVTerm::createArea ( int offset_left, int offset_top
{
// 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);
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 )
delete[] area->text;
area->changes = new line_changes[height + bsh];
area->text = new char_data[area_size];
try
{
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 )
{
if ( area->text != 0 )
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
return;
@ -2221,8 +2254,17 @@ void FVTerm::init()
init_object = this;
vterm = 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
hidden_cursor = \

View File

@ -2276,10 +2276,19 @@ void FWidget::onClose (FCloseEvent* ev)
//----------------------------------------------------------------------
void FWidget::init()
{
window_list = new widgetList();
dialog_list = new widgetList();
always_on_top_list = new widgetList();
close_widget = new widgetList();
try
{
// Initialize widget lists
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();
@ -2290,7 +2299,7 @@ void FWidget::init()
visible_cursor = ! hideable;
// determine width and height of the terminal
// Determine width and height of the terminal
detectTermSize();
wsize.setRect(1, 1, getColumnNumber(), getLineNumber());
adjust_wsize = wsize;
@ -2309,7 +2318,14 @@ void FWidget::init()
background_color = wc.term_bg;
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;
}
}
//----------------------------------------------------------------------