memory management + handling environment variables with numbers

This commit is contained in:
Markus Gans 2018-11-24 23:43:09 +01:00
parent 6c4ba7af89
commit c15cb0ba24
6 changed files with 57 additions and 24 deletions

View File

@ -7,7 +7,8 @@
2018-11-18 Markus Gans <guru.mail@muenster.de>
* The FListViewItem class now provides checkable list view items
* Adding the checklist example to demonstrate the checkable FListViewItems
* Adding the checklist example to demonstrate the checkable
FListViewItems
* A checkable FListViewItem now shows the input cursor
2018-11-12 Markus Gans <guru.mail@muenster.de>

View File

@ -43,7 +43,7 @@ fi
# Build commands
case "$1" in
"--release"|"release")
if ! ./configure --prefix="$PREFIX" CXXFLAGS="-O3 -fno-rtti"
if ! ./configure --prefix="$PREFIX" CXXFLAGS="-O2" # "-O3 -fno-rtti"
then
echo "${RED}Configure failed!${NORMAL}" 1>&2
exit -1

View File

@ -184,9 +184,9 @@ class MainWindow : public finalcut::FDialog
// Data Members
finalcut::FString line1;
finalcut::FString line2;
Transparent transpwin;
Transparent shadowwin;
Transparent ibg;
Transparent* transpwin;
Transparent* shadowwin;
Transparent* ibg;
finalcut::FStatusBar status_bar;
};
#pragma pack(pop)
@ -196,25 +196,32 @@ MainWindow::MainWindow (finalcut::FWidget* parent)
: FDialog(parent)
, line1()
, line2()
, transpwin(this)
, shadowwin(this, Transparent::shadow)
, ibg(this, Transparent::inherit_background)
, transpwin(0)
, shadowwin(0)
, ibg(0)
, status_bar(this)
{
line1 = " .-. .-. .-.";
line2 = "`._.' `._.' `._.' ";
transpwin.setText("transparent");
transpwin.setGeometry (6, 3, 29, 12);
transpwin.unsetTransparentShadow();
// The memory allocation for the following three sub windows occurs
// with the operator new. The lifetime of the generated widget
// is managed by the parent object (this). The operator delete
// is not required in this scope and would result in a double free.
transpwin = new Transparent(this);
transpwin->setText("transparent");
transpwin->setGeometry (6, 3, 29, 12);
transpwin->unsetTransparentShadow();
shadowwin.setText("shadow");
shadowwin.setGeometry (46, 11, 29, 12);
shadowwin.unsetTransparentShadow();
shadowwin = new Transparent(this, Transparent::shadow);
shadowwin->setText("shadow");
shadowwin->setGeometry (46, 11, 29, 12);
shadowwin->unsetTransparentShadow();
ibg.setText("inherit background");
ibg.setGeometry (42, 3, 29, 7);
ibg.unsetTransparentShadow();
ibg = new Transparent(this, Transparent::inherit_background);
ibg->setText("inherit background");
ibg->setGeometry (42, 3, 29, 7);
ibg->unsetTransparentShadow();
// Statusbar at the bottom
status_bar.setMessage("Press Q to quit");

View File

@ -646,11 +646,13 @@ int FOptiMove::repeatedAppend ( const capability& o
if ( dst )
{
dst += dst_len;
std::size_t free = BUF_SIZE - dst_len;
while ( count-- > 0 )
{
std::strncpy (dst, o.cap, src_len + 1);
std::strncpy (dst, o.cap, free);
dst += src_len;
free -= src_len;
}
}
}

View File

@ -63,6 +63,9 @@ FMouseControl* FTerm::mouse = 0;
FTermDebugData* FTerm::debug_data = 0;
#endif
// function prototypes
uInt env2uint (const char*);
//----------------------------------------------------------------------
// class FTerm
@ -487,11 +490,11 @@ void FTerm::detectTermSize()
{
term_geometry.setPos (1, 1);
// Use COLUMNS or fallback to the xterm default width of 80 characters
char* Columns = std::getenv("COLUMNS");
term_geometry.setWidth(Columns ? std::size_t(std::atoi(Columns)) : 80);
uInt Columns = env2uint ("COLUMNS");
term_geometry.setWidth( ( Columns == 0) ? 80 : Columns);
// Use LINES or fallback to the xterm default height of 24 characters
char* Lines = std::getenv("LINES");
term_geometry.setHeight(Lines ? std::size_t(std::atoi(Lines)) : 24);
uInt Lines = env2uint ("LINES");
term_geometry.setHeight( ( Lines == 0 ) ? 24 : Lines);
}
else
{
@ -2072,6 +2075,26 @@ void FTerm::signal_handler (int signum)
, strsignal(signum) );
std::terminate();
}
}
// FTerm non-member functions
//----------------------------------------------------------------------
uInt env2uint (const char* env)
{
FString str(env);
if ( str.isEmpty() )
return 0;
try
{
return str.toUInt();
}
catch (const std::exception& ex)
{
return 0;
}
}
} // namespace finalcut

View File

@ -2314,7 +2314,7 @@ void FTermDetectionTest::terminalSimulation (console con)
{
len = read (fd_stdin, buffer, sizeof(buffer));
if ( len != -1 && std::size_t(len) < sizeof(buffer) )
if ( len > 0 && std::size_t(len) < sizeof(buffer) )
{
buffer[len] = '\0';
write (fd_master, buffer, len); // Send data to the master side