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> 2018-11-18 Markus Gans <guru.mail@muenster.de>
* The FListViewItem class now provides checkable list view items * 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 * A checkable FListViewItem now shows the input cursor
2018-11-12 Markus Gans <guru.mail@muenster.de> 2018-11-12 Markus Gans <guru.mail@muenster.de>

View File

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

View File

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

View File

@ -646,11 +646,13 @@ int FOptiMove::repeatedAppend ( const capability& o
if ( dst ) if ( dst )
{ {
dst += dst_len; dst += dst_len;
std::size_t free = BUF_SIZE - dst_len;
while ( count-- > 0 ) while ( count-- > 0 )
{ {
std::strncpy (dst, o.cap, src_len + 1); std::strncpy (dst, o.cap, free);
dst += src_len; dst += src_len;
free -= src_len;
} }
} }
} }
@ -793,7 +795,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x)
// Move to fixed column position1 // Move to fixed column position1
std::strncat ( hmove std::strncat ( hmove
, tparm(F_column_address.cap, to_x, 0, 0, 0, 0, 0, 0, 0, 0) , tparm(F_column_address.cap, to_x, 0, 0, 0, 0, 0, 0, 0, 0)
, BUF_SIZE - std::strlen(hmove) - 1); , BUF_SIZE - std::strlen(hmove) - 1 );
hmove[BUF_SIZE - 1] = '\0'; hmove[BUF_SIZE - 1] = '\0';
htime = F_column_address.duration; htime = F_column_address.duration;
} }

View File

@ -63,6 +63,9 @@ FMouseControl* FTerm::mouse = 0;
FTermDebugData* FTerm::debug_data = 0; FTermDebugData* FTerm::debug_data = 0;
#endif #endif
// function prototypes
uInt env2uint (const char*);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FTerm // class FTerm
@ -487,11 +490,11 @@ void FTerm::detectTermSize()
{ {
term_geometry.setPos (1, 1); term_geometry.setPos (1, 1);
// Use COLUMNS or fallback to the xterm default width of 80 characters // Use COLUMNS or fallback to the xterm default width of 80 characters
char* Columns = std::getenv("COLUMNS"); uInt Columns = env2uint ("COLUMNS");
term_geometry.setWidth(Columns ? std::size_t(std::atoi(Columns)) : 80); term_geometry.setWidth( ( Columns == 0) ? 80 : Columns);
// Use LINES or fallback to the xterm default height of 24 characters // Use LINES or fallback to the xterm default height of 24 characters
char* Lines = std::getenv("LINES"); uInt Lines = env2uint ("LINES");
term_geometry.setHeight(Lines ? std::size_t(std::atoi(Lines)) : 24); term_geometry.setHeight( ( Lines == 0 ) ? 24 : Lines);
} }
else else
{ {
@ -2072,6 +2075,26 @@ void FTerm::signal_handler (int signum)
, strsignal(signum) ); , strsignal(signum) );
std::terminate(); 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 } // namespace finalcut

View File

@ -2314,7 +2314,7 @@ void FTermDetectionTest::terminalSimulation (console con)
{ {
len = read (fd_stdin, buffer, sizeof(buffer)); 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'; buffer[len] = '\0';
write (fd_master, buffer, len); // Send data to the master side write (fd_master, buffer, len); // Send data to the master side