From 2a50d35e71806f818e328dfcb1923cf1ef978988 Mon Sep 17 00:00:00 2001 From: wfjm Date: Sun, 28 Oct 2018 12:19:19 +0100 Subject: [PATCH] some minor c++11 and -Weverything code updates - use `nullptr` instead of plain '0' - use `[[noreturn]]` (clang -Wmissing-noreturn) - drop never reached returns (clang -Wunreachable-code-return) - drop `throw()` lists, use `noexcept` (clang -Wdeprecated) - add `R*_Init` prototypes (clang -Wmissing-prototypes) - Rw11VirtEthTap.cpp: BUGFIX: buffer not null terminated (coverity) --- doc/CHANGELOG.md | 10 ++++++++-- tools/src/librlink/RlinkCommand.cpp | 6 +++--- tools/src/librlink/RlinkPortCuff.cpp | 4 +++- tools/src/librlink/RlinkPortCuff.hpp | 8 ++++---- tools/src/librlinktpp/Rlinktpp_Init.cpp | 6 ++++-- tools/src/librtools/Rexception.cpp | 9 +++++---- tools/src/librtools/Rexception.hpp | 9 +++++---- tools/src/librtools/RiosState.cpp | 6 +++--- tools/src/librtools/Rstats.cpp | 6 +++--- tools/src/librutiltpp/Rutiltpp_Init.cpp | 6 ++++-- tools/src/librw11/Rw11UnitDisk.cpp | 3 +-- tools/src/librw11/Rw11UnitTape.cpp | 3 +-- tools/src/librw11/Rw11VirtEthTap.cpp | 4 ++-- tools/src/librwxxtpp/Rwxxtpp_Init.cpp | 6 ++++-- 14 files changed, 50 insertions(+), 36 deletions(-) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index e394e94e..c6ccb96b 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -64,20 +64,26 @@ The full set of tests is only run for tagged releases. - sys_w11a_*.vhd: use DM_STAT_EXP; IDEC to maxisys; setup PERFEXT - RtclRw11Unit: fix for clang: M_virt() now public - backend code review: - - use for C++ compiles also `-Wpedantic` + - use for C++ compiles `-Wpedantic` (in addition to `-Wall` and `-Wextra`) - fixes for uninitialized variables (coverity, all uncritical) - catch exceptions in dtors (coverity, use Catch2Cerr) + - use `nullptr` instead of plain '0' + - use `[[noreturn]]` (clang -Wmissing-noreturn) + - drop never reached returns (clang -Wunreachable-code-return) + - drop `throw()` lists, use `noexcept` (clang -Wdeprecated) + - add `R*_Init` prototypes (clang -Wmissing-prototypes) - now -Wunused-parameter clean (comment out unused params) - now -Wunused-variable clean (comment out so far unused code) - move `using namespace std` after includes (clang warning) - some selected clang -Weverything aspects - - now -Wdocumentation clean (some wrong doxygen trailing comments) + - now -Wdocumentation clean (some wrong doxygen trailing comments) ### Bug Fixes - RtclArgs.hpp: BUGFIX: get *_min limits correct (gcc -Wpedantic) - RtclArgs.cpp: BUGFIX: GetArg(): argument in wrong order (coverity) - Rw11CntlDEUNA.cpp: BUGFIX: SetMacDefault(): resource leak (coverity) - Rw11VirtDiskFile.cpp: BUGFIX: Open(): resource leak (coverity) +- Rw11VirtEthTap.cpp: BUGFIX: buffer not null terminated (coverity) - Rw11VirtTapeTap.cpp: - BUGFIX: Open(): resource leak (coverity) - BUGFIX: Rewind(): bad constant expression (coverity) diff --git a/tools/src/librlink/RlinkCommand.cpp b/tools/src/librlink/RlinkCommand.cpp index 70f95390..57d1610e 100644 --- a/tools/src/librlink/RlinkCommand.cpp +++ b/tools/src/librlink/RlinkCommand.cpp @@ -1,6 +1,6 @@ -// $Id: RlinkCommand.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RlinkCommand.cpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2011-2017 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -240,7 +240,7 @@ void RlinkCommand::SetBlockRead(size_t size) void RlinkCommand::SetBlockExt(uint16_t* pblock, size_t size) { - if (pblock == 0) + if (pblock == nullptr) throw Rexception("RlinkCommand::SetBlockExt()", "Bad args: pblock is null"); if (size == 0 || size > 65535) diff --git a/tools/src/librlink/RlinkPortCuff.cpp b/tools/src/librlink/RlinkPortCuff.cpp index 67dc2fba..66296857 100644 --- a/tools/src/librlink/RlinkPortCuff.cpp +++ b/tools/src/librlink/RlinkPortCuff.cpp @@ -1,4 +1,4 @@ -// $Id: RlinkPortCuff.cpp 1059 2018-10-27 10:34:16Z mueller $ +// $Id: RlinkPortCuff.cpp 1060 2018-10-27 11:32:39Z mueller $ // // Copyright 2012-2018 by Walter F.J. Mueller // @@ -509,6 +509,7 @@ bool RlinkPortCuff::TraceOn() //------------------------------------------+----------------------------------- //! FIXME_docs +[[noreturn]] void RlinkPortCuff::BadSysCall(const char* meth, const char* text, int rc) { stringstream ss; @@ -520,6 +521,7 @@ void RlinkPortCuff::BadSysCall(const char* meth, const char* text, int rc) //------------------------------------------+----------------------------------- //! FIXME_docs +[[noreturn]] void RlinkPortCuff::BadUSBCall(const char* meth, const char* text, int rc) { stringstream ss; diff --git a/tools/src/librlink/RlinkPortCuff.hpp b/tools/src/librlink/RlinkPortCuff.hpp index bc7d53f2..3c8803a3 100644 --- a/tools/src/librlink/RlinkPortCuff.hpp +++ b/tools/src/librlink/RlinkPortCuff.hpp @@ -1,6 +1,6 @@ -// $Id: RlinkPortCuff.hpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RlinkPortCuff.hpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2012-2013 by Walter F.J. Mueller +// Copyright 2012-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -91,8 +91,8 @@ namespace Retro { void DriverEventUSB(); libusb_transfer* NewWriteTransfer(); bool TraceOn(); - void BadSysCall(const char* meth, const char* text, int rc); - void BadUSBCall(const char* meth, const char* text, int rc); + [[noreturn]] void BadSysCall(const char* meth, const char* text, int rc); + [[noreturn]] void BadUSBCall(const char* meth, const char* text, int rc); void CheckUSBTransfer(const char* meth, libusb_transfer *t); const char* USBErrorName(int rc); diff --git a/tools/src/librlinktpp/Rlinktpp_Init.cpp b/tools/src/librlinktpp/Rlinktpp_Init.cpp index 95fb20d9..3e1dea7b 100644 --- a/tools/src/librlinktpp/Rlinktpp_Init.cpp +++ b/tools/src/librlinktpp/Rlinktpp_Init.cpp @@ -1,6 +1,6 @@ -// $Id: Rlinktpp_Init.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rlinktpp_Init.cpp 1061 2018-10-27 17:39:11Z mueller $ // -// Copyright 2011-2014 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -40,6 +40,8 @@ using namespace std; using namespace Retro; +extern "C" int Rlinktpp_Init(Tcl_Interp* interp); // -Wmissing-prototypes fix + //------------------------------------------+----------------------------------- extern "C" int Rlinktpp_Init(Tcl_Interp* interp) { diff --git a/tools/src/librtools/Rexception.cpp b/tools/src/librtools/Rexception.cpp index e8da4bef..ff2b018a 100644 --- a/tools/src/librtools/Rexception.cpp +++ b/tools/src/librtools/Rexception.cpp @@ -1,6 +1,6 @@ -// $Id: Rexception.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rexception.cpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2013-2017 by Walter F.J. Mueller +// Copyright 2013-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1060 1.3 drop throw() list; use noexcept // 2017-04-29 888 1.2 BUGFIX: add fErrtxt for proper what() return // 2014-12-30 625 1.1 add ctor(meth,text,emsg) // 2013-01-12 474 1.0 Initial version @@ -81,13 +82,13 @@ Rexception::Rexception(const std::string& meth, const std::string& text, //------------------------------------------+----------------------------------- //! Destructor -Rexception::~Rexception() throw() +Rexception::~Rexception() {} //------------------------------------------+----------------------------------- //! FIXME_docs -const char* Rexception::what() const throw() +const char* Rexception::what() const noexcept { // what() must return a pointer to a string which stays valid at least as long // as the exception object lives. Use member variable fErrtxt for this. diff --git a/tools/src/librtools/Rexception.hpp b/tools/src/librtools/Rexception.hpp index e630a29c..060de876 100644 --- a/tools/src/librtools/Rexception.hpp +++ b/tools/src/librtools/Rexception.hpp @@ -1,6 +1,6 @@ -// $Id: Rexception.hpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rexception.hpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2013-2017 by Walter F.J. Mueller +// Copyright 2013-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-27 1060 1.3 drop throw() list; use noexcept // 2017-04-29 888 1.2 BUGFIX: add fErrtxt for proper what() return // 2014-12-30 625 1.1 add ctor(meth,text,emsg) // 2013-02-12 487 1.0.1 add ErrMsg() getter @@ -45,9 +46,9 @@ namespace Retro { const std::string& text, int errnum); Rexception(const std::string& meth, const std::string& text, const RerrMsg& errmsg); - ~Rexception() throw(); + ~Rexception(); - virtual const char* what() const throw(); + virtual const char* what() const noexcept; const RerrMsg& ErrMsg() const; protected: diff --git a/tools/src/librtools/RiosState.cpp b/tools/src/librtools/RiosState.cpp index ca7122b4..efa3160f 100644 --- a/tools/src/librtools/RiosState.cpp +++ b/tools/src/librtools/RiosState.cpp @@ -1,6 +1,6 @@ -// $Id: RiosState.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RiosState.cpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2006-2011 by Walter F.J. Mueller +// Copyright 2006-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -82,7 +82,7 @@ void RiosState::SetFormat(const char* form, int prec) char c_fill = 0; char c; - if (form == 0) form = ""; // allow null as format + if (form == nullptr) form = ""; // allow null as format for (c = *form++; ; c = *form++) { if (c == '+') { b_plus = true; continue;} diff --git a/tools/src/librtools/Rstats.cpp b/tools/src/librtools/Rstats.cpp index 79c142d5..33f3f254 100644 --- a/tools/src/librtools/Rstats.cpp +++ b/tools/src/librtools/Rstats.cpp @@ -1,6 +1,6 @@ -// $Id: Rstats.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rstats.cpp 1060 2018-10-27 11:32:39Z mueller $ // -// Copyright 2011-2017 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -156,7 +156,7 @@ size_t Rstats::NameMaxLength() const void Rstats::Print(std::ostream& os, const char* format, int width, int prec) const { - if (format == 0 || format[0]==0) { + if (format == nullptr || format[0]==0) { format = fFormat.c_str(); width = fWidth; prec = fPrec; diff --git a/tools/src/librutiltpp/Rutiltpp_Init.cpp b/tools/src/librutiltpp/Rutiltpp_Init.cpp index 5bd62820..e507455b 100644 --- a/tools/src/librutiltpp/Rutiltpp_Init.cpp +++ b/tools/src/librutiltpp/Rutiltpp_Init.cpp @@ -1,6 +1,6 @@ -// $Id: Rutiltpp_Init.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rutiltpp_Init.cpp 1061 2018-10-27 17:39:11Z mueller $ // -// Copyright 2011-2014 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -35,6 +35,8 @@ using namespace std; using namespace Retro; +extern "C" int Rutiltpp_Init(Tcl_Interp* interp); // -Wmissing-prototypes fix + //------------------------------------------+----------------------------------- extern "C" int Rutiltpp_Init(Tcl_Interp* interp) { diff --git a/tools/src/librw11/Rw11UnitDisk.cpp b/tools/src/librw11/Rw11UnitDisk.cpp index b925d47f..f7f07f88 100644 --- a/tools/src/librw11/Rw11UnitDisk.cpp +++ b/tools/src/librw11/Rw11UnitDisk.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11UnitDisk.cpp 1049 2018-09-22 13:56:52Z mueller $ +// $Id: Rw11UnitDisk.cpp 1060 2018-10-27 11:32:39Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -66,7 +66,6 @@ void Rw11UnitDisk::SetType(const std::string& /*type*/) { throw Rexception("Rw11UnitDisk::SetType", string("Bad args: only type '") + fType + "' supported"); - return; } //------------------------------------------+----------------------------------- diff --git a/tools/src/librw11/Rw11UnitTape.cpp b/tools/src/librw11/Rw11UnitTape.cpp index a23d8346..fb17267c 100644 --- a/tools/src/librw11/Rw11UnitTape.cpp +++ b/tools/src/librw11/Rw11UnitTape.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11UnitTape.cpp 1049 2018-09-22 13:56:52Z mueller $ +// $Id: Rw11UnitTape.cpp 1060 2018-10-27 11:32:39Z mueller $ // // Copyright 2015-2018 by Walter F.J. Mueller // @@ -61,7 +61,6 @@ void Rw11UnitTape::SetType(const std::string& /*type*/) { throw Rexception("Rw11UnitTape::SetType", string("Bad args: only type '") + fType + "' supported"); - return; } //------------------------------------------+----------------------------------- diff --git a/tools/src/librw11/Rw11VirtEthTap.cpp b/tools/src/librw11/Rw11VirtEthTap.cpp index 6f9eb985..9737dd05 100644 --- a/tools/src/librw11/Rw11VirtEthTap.cpp +++ b/tools/src/librw11/Rw11VirtEthTap.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtEthTap.cpp 1059 2018-10-27 10:34:16Z mueller $ +// $Id: Rw11VirtEthTap.cpp 1062 2018-10-28 11:14:20Z mueller $ // // Copyright 2014-2018 by Walter F.J. Mueller // @@ -14,7 +14,7 @@ // Revision History: // Date Rev Version Comment // 2018-10-27 1059 1.0.1 coverity fixup (uncaught exception in dtor) -// coverity fixup (buffer not null terminated) +// BUGFIX: coverity (buffer not null terminated) // 2017-04-15 875 1.0 Initial version // 2014-06-09 561 0.1 First draft // --------------------------------------------------------------------------- diff --git a/tools/src/librwxxtpp/Rwxxtpp_Init.cpp b/tools/src/librwxxtpp/Rwxxtpp_Init.cpp index 81296509..fcbfdda4 100644 --- a/tools/src/librwxxtpp/Rwxxtpp_Init.cpp +++ b/tools/src/librwxxtpp/Rwxxtpp_Init.cpp @@ -1,6 +1,6 @@ -// $Id: Rwxxtpp_Init.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rwxxtpp_Init.cpp 1061 2018-10-27 17:39:11Z mueller $ // -// Copyright 2013-2014 by Walter F.J. Mueller +// Copyright 2013-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -33,6 +33,8 @@ using namespace std; using namespace Retro; +extern "C" int Rwxxtpp_Init(Tcl_Interp* interp); // -Wmissing-prototypes fix + //------------------------------------------+----------------------------------- extern "C" int Rwxxtpp_Init(Tcl_Interp* interp) {