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
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;
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(' ');
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;
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;
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,12 +767,21 @@ void FDialog::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getTermPos();
const FPoint& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton();
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;
}
}
}
if ( mouse_x > getWidth() - zoom_btn && mouse_y == 1 && zoom_button_active )
@ -1058,9 +1067,27 @@ void FDialog::init()
old_focus->redraw();
}
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
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();
}
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)
);
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)
);
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
@ -1429,7 +1483,16 @@ void FDialog::cb_move (FWidget*, data_ptr)
setReverse(false);
save_geometry = getGeometry();
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("*");
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("*");
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,6 +506,8 @@ void FFileDialog::init()
else
FDialog::setText("Open file");
try
{
filename = new FLineEdit(this);
filename->setLabelText("File&name");
filename->setText(filter_pattern);
@ -513,6 +531,12 @@ void FFileDialog::init()
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;
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,10 +189,19 @@ void FLabel::onMouseDown (FMouseEvent* ev)
int b = ev->getButton();
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
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();
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();
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;
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;
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;
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,6 +1243,8 @@ void FListBox::init()
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
@ -1234,6 +1254,12 @@ void FListBox::init()
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 )
{
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,6 +882,8 @@ void FListView::init()
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
@ -883,6 +893,12 @@ void FListView::init()
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)
{
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();
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();
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();
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());
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;
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,12 +417,20 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
const FPoint& t = ev->getTermPos();
const FPoint& p = menu->termToWidgetPos(t);
int b = ev->getButton();
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());
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,10 +333,18 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->termToWidgetPos(t);
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;
}
}
}
if ( isMenuBar(super_menu) )
@ -346,10 +354,18 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( mbar )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
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;
}
}
}
if ( isWindowsMenu(super_menu) )
@ -359,10 +375,18 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev)
if ( dgl )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
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,10 +406,18 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->termToWidgetPos(t);
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;
}
}
}
if ( isMenuBar(super_menu) )
@ -395,10 +427,18 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( mbar )
{
const FPoint& p2 = mbar->termToWidgetPos(t);
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;
}
}
}
if ( isWindowsMenu(super_menu) )
@ -408,10 +448,18 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( dgl )
{
const FPoint& p2 = dgl->termToWidgetPos(t);
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();
try
{
// create a new dialog list item
FMenuItem* win_item = new FMenuItem (name, winmenu);
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
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
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
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,6 +311,8 @@ void FMessageBox::init (int button0, int button1, int button2)
button_digit[1] = button1;
button_digit[2] = button2;
try
{
button[0] = new FButton (this);
button[0]->setText(button_text[button0]);
button[0]->setPos(3, getHeight()-4, false);
@ -302,6 +337,12 @@ void FMessageBox::init (int button0, int button1, int button2)
button[2]->setWidth(0, false);
button[2]->setHeight(1, false);
}
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
resizeButtons();
adjustButtons();

View File

@ -31,11 +31,31 @@ FObject::FObject (FObject* parent)
timer_modify_lock = false;
if ( ! timer_list )
{
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 )
{
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 )
{
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;
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,6 +762,8 @@ void FScrollView::init (FWidget* parent)
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
@ -771,6 +773,12 @@ void FScrollView::init (FWidget* parent)
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;
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

@ -527,8 +527,17 @@ FString& FString::sprintf (const char* format, ...)
va_end (args);
if ( len >= int(sizeof(buf)) )
{
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;
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
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
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,9 +2702,9 @@ 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)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return new_termtype;
}
@ -3580,13 +3620,21 @@ void FTerm::init()
term_initialized = true;
init_term_object = this;
fd_tty = -1;
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

@ -51,8 +51,17 @@ int FTermBuffer::writef (const char* format, ...)
va_end (args);
if ( len >= int(sizeof(buf)) )
{
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;
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;
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,10 +437,18 @@ void FTextView::onMouseDown (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus();
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,10 +467,18 @@ void FTextView::onMouseUp (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus();
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() )
vbar->redraw();
@ -469,10 +503,18 @@ void FTextView::onMouseMove (FMouseEvent* ev)
const FPoint& tp = ev->getTermPos();
const FPoint& p = parent->termToWidgetPos(tp);
parent->setFocus();
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,6 +646,8 @@ void FTextView::init()
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
try
{
vbar = new FScrollbar(fc::vertical, this);
vbar->setMinimum(0);
vbar->setValue(0);
@ -613,6 +657,12 @@ void FTextView::init()
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;
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;
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

@ -316,8 +316,16 @@ int FVTerm::printf (const char* format, ...)
va_end (args);
if ( len >= int(sizeof(buf)) )
{
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
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,16 +983,32 @@ void FVTerm::resizeArea ( int offset_left, int offset_top
if ( area->text != 0 )
delete[] area->text;
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;
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;
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()
{
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;
try
{
accelerator_list = new Accelerators();
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
}
}
//----------------------------------------------------------------------