From 3678d527665de15c788aa57562f62f25b868fe5f Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 22 Oct 2018 01:26:24 +0200 Subject: [PATCH] Small code fixes --- src/fdialog.cpp | 8 ++------ src/fdialoglistmenu.cpp | 4 +--- src/flineedit.cpp | 3 +-- src/foptimove.cpp | 4 ++-- src/fterm.cpp | 2 +- src/ftermlinux.cpp | 11 +++-------- src/include/final/fpoint.h | 10 +++++----- test/fkeyboard-test.cpp | 2 +- test/fobject-test.cpp | 8 +++++--- test/fpoint-test.cpp | 6 ++++-- test/frect-test.cpp | 4 +++- 11 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 0542e912..bad4c777 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -925,12 +925,8 @@ void FDialog::initDialogMenu() dialog_menu->setPos (getX(), getY() + 1); dgl_menuitem = dialog_menu->getItem(); - - if ( dgl_menuitem ) - { - dgl_menuitem->ignorePadding(); - dgl_menuitem->unsetFocusable(); - } + dgl_menuitem->ignorePadding(); + dgl_menuitem->unsetFocusable(); // Add the move/size menu item initMoveSizeMenuItem (dialog_menu); diff --git a/src/fdialoglistmenu.cpp b/src/fdialoglistmenu.cpp index c7ebff1c..fec9d201 100644 --- a/src/fdialoglistmenu.cpp +++ b/src/fdialoglistmenu.cpp @@ -54,9 +54,7 @@ FDialogListMenu::~FDialogListMenu() void FDialogListMenu::init() { FMenuItem* menuitem = getItem(); - - if ( menuitem ) - menuitem->dialog_index = true; + menuitem->dialog_index = true; } } // namespace finalcut diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 050a376b..a1bef7b3 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -529,8 +529,7 @@ void FLineEdit::onTimer (FTimerEvent*) return; } - if ( text_offset > 0 ) - text_offset--; + text_offset--; if ( cursor_pos > 0 ) cursor_pos--; diff --git a/src/foptimove.cpp b/src/foptimove.cpp index dfbc3471..d20ff575 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -1154,11 +1154,11 @@ void FOptiMove::moveByMethod ( int method if ( xold >= 0 ) std::strncat ( move_ptr , F_carriage_return.cap - , BUF_SIZE - std::strlen(move_ptr) ); + , BUF_SIZE - std::strlen(move_ptr) - 1 ); std::strncat ( move_ptr , F_cursor_left.cap - , BUF_SIZE - std::strlen(move_ptr) ); + , BUF_SIZE - std::strlen(move_ptr) - 1); move_ptr[BUF_SIZE - 1] ='\0'; move_ptr += std::strlen(move_buf); relativeMove (move_ptr, int(screen_width) - 1, yold - 1, xnew, ynew); diff --git a/src/fterm.cpp b/src/fterm.cpp index dfd3588d..246efefc 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -416,7 +416,7 @@ char* FTerm::enableCursor() // Restore the last used Linux console cursor style char* cstyle; cstyle = linux->restoreCursorStyle(); - std::strncat (enable_str, cstyle, SIZE - std::strlen(enable_str)); + std::strncat (enable_str, cstyle, SIZE - std::strlen(enable_str) - 1); } #endif // defined(__linux__) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 8dec6fc7..e1b9e639 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -577,19 +577,14 @@ bool FTermLinux::getUnicodeMap() if ( ret != 0 ) { - int count; + std::size_t count = screen_unicode_map.entry_ct; - if ( errno != ENOMEM || screen_unicode_map.entry_ct == 0 ) - return false; - - count = screen_unicode_map.entry_ct; - - if ( count <= 0 ) + if ( errno != ENOMEM || count == 0 ) return false; try { - screen_unicode_map.entries = new struct unipair[std::size_t(count)](); + screen_unicode_map.entries = new struct unipair[count](); } catch (const std::bad_alloc& ex) { diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 9e4fc746..44c68172 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -63,11 +63,11 @@ class FPoint FPoint& operator += (const FPoint&); FPoint& operator -= (const FPoint&); - friend inline bool operator == (const FPoint&, const FPoint&); - friend inline bool operator != (const FPoint&, const FPoint&); - friend inline FPoint operator + (const FPoint&, const FPoint&); - friend inline FPoint operator - (const FPoint&, const FPoint&); - friend inline FPoint operator - (const FPoint&); + friend bool operator == (const FPoint&, const FPoint&); + friend bool operator != (const FPoint&, const FPoint&); + friend FPoint operator + (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&, const FPoint&); + friend FPoint operator - (const FPoint&); friend std::ostream& operator << (std::ostream&, const FPoint&); friend std::istream& operator >> (std::istream&, FPoint&); diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index 7d5c5099..e919c384 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -2763,7 +2763,7 @@ void FKeyboardTest::utf8Test() keyboard->disableUTF8(); input("\360\220\200\200"); processInput(); - CPPUNIT_ASSERT ( key_released == 0200 ); + CPPUNIT_ASSERT ( key_released == 128 ); clear(); } diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index c7543b71..6dac3f6c 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -131,6 +131,7 @@ void FObjectTest::classNameTest() void FObjectTest::noArgumentTest() { finalcut::FObject o1; + finalcut::FObject o2; CPPUNIT_ASSERT ( ! o1.hasParent() ); CPPUNIT_ASSERT ( o1.getParent() == 0 ); CPPUNIT_ASSERT ( ! o1.hasChildren() ); @@ -142,8 +143,8 @@ void FObjectTest::noArgumentTest() CPPUNIT_ASSERT ( children_list.begin() == o1.end() ); CPPUNIT_ASSERT ( children_list.end() == o1.begin() ); CPPUNIT_ASSERT ( children_list.end() == o1.end() ); - CPPUNIT_ASSERT ( ! o1.isChild(&o1) ); - CPPUNIT_ASSERT ( ! o1.isDirectChild(&o1) ); + CPPUNIT_ASSERT ( ! o1.isChild(&o2) ); + CPPUNIT_ASSERT ( ! o1.isDirectChild(&o2) ); CPPUNIT_ASSERT ( ! o1.isWidget() ); CPPUNIT_ASSERT ( o1.isInstanceOf("FObject") ); CPPUNIT_ASSERT ( ! o1.isTimerInUpdating() ); @@ -176,6 +177,7 @@ void FObjectTest::childObjectTest() finalcut::FObject* c4 = new finalcut::FObject(&obj); finalcut::FObject* c5 = new finalcut::FObject(c1); finalcut::FObject* c6 = new finalcut::FObject(c5); + finalcut::FObject* c7 = new finalcut::FObject(); CPPUNIT_ASSERT ( obj.hasChildren() ); CPPUNIT_ASSERT ( obj.getChild(0) == 0 ); @@ -213,7 +215,7 @@ void FObjectTest::childObjectTest() CPPUNIT_ASSERT ( children_list2.begin() != c1->end() ); CPPUNIT_ASSERT ( children_list2.end() != c1->begin() ); CPPUNIT_ASSERT ( children_list2.end() == c1->end() ); - CPPUNIT_ASSERT ( ! c1->isDirectChild(c1) ); + CPPUNIT_ASSERT ( ! c1->isDirectChild(c7) ); CPPUNIT_ASSERT ( ! c1->isWidget() ); CPPUNIT_ASSERT ( c1->isInstanceOf("FObject") ); CPPUNIT_ASSERT ( ! c1->isTimerInUpdating() ); diff --git a/test/fpoint-test.cpp b/test/fpoint-test.cpp index e0cfe327..771031ea 100644 --- a/test/fpoint-test.cpp +++ b/test/fpoint-test.cpp @@ -219,8 +219,10 @@ void FPointTest::equalTest() CPPUNIT_ASSERT ( p1 == p2 ); CPPUNIT_ASSERT ( finalcut::FPoint(1,2) == p2 ); CPPUNIT_ASSERT ( p1 == finalcut::FPoint(1,2) ); - CPPUNIT_ASSERT ( finalcut::FPoint() == finalcut::FPoint() ); - CPPUNIT_ASSERT ( finalcut::FPoint() == -finalcut::FPoint() ); + const finalcut::FPoint p3; + const finalcut::FPoint p4; + CPPUNIT_ASSERT ( p3 == p4 ); + CPPUNIT_ASSERT ( p3 == -p4 ); } //---------------------------------------------------------------------- diff --git a/test/frect-test.cpp b/test/frect-test.cpp index 913eb3c3..fe3c024d 100644 --- a/test/frect-test.cpp +++ b/test/frect-test.cpp @@ -299,7 +299,9 @@ void FRectTest::equalTest() CPPUNIT_ASSERT ( r1 == r2 ); CPPUNIT_ASSERT ( finalcut::FRect(1, 2, 10, 20) == r2 ); CPPUNIT_ASSERT ( r1 == finalcut::FRect(1, 2, 10, 20) ); - CPPUNIT_ASSERT ( finalcut::FRect() == finalcut::FRect() ); + const finalcut::FRect r3; + const finalcut::FRect r4; + CPPUNIT_ASSERT ( r3 == r4 ); } //----------------------------------------------------------------------