diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 89e17c70..1998223e 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -87,6 +87,7 @@ The full set of tests is only run for tagged releases. - move `using namespace std` after includes (clang warning) - some selected clang -Weverything aspects - now -Wdocumentation clean (some wrong doxygen trailing comments) + - use auto, emplace() and range loops - rw11/shell.tcl: add workaround for tclreadline and `after` interference ### Bug Fixes diff --git a/tools/src/librlink/RlinkAddrMap.cpp b/tools/src/librlink/RlinkAddrMap.cpp index 59b6350a..9fb3115b 100644 --- a/tools/src/librlink/RlinkAddrMap.cpp +++ b/tools/src/librlink/RlinkAddrMap.cpp @@ -1,4 +1,4 @@ -// $Id: RlinkAddrMap.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RlinkAddrMap.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2011-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.0.4 use auto; use emplace,make_pair +// 2018-11-16 1070 1.0.4 use auto; use emplace,make_pair; use range loop // 2017-04-07 868 1.0.3 Dump(): add detail arg // 2013-02-03 481 1.0.2 use Rexception // 2011-11-28 434 1.0.1 Print(): use proper cast for lp64 compatibility @@ -154,8 +154,8 @@ bool RlinkAddrMap::Find(uint16_t addr, std::string& name) const size_t RlinkAddrMap::MaxNameLength() const { if (fMaxLength == 0) { - for (auto it=fAddrMap.begin(); it!=fAddrMap.end(); it++) { - fMaxLength = max(fMaxLength, (it->second).length()); + for (auto& o: fAddrMap) { + fMaxLength = max(fMaxLength, o.second.length()); } } return fMaxLength; @@ -166,13 +166,13 @@ size_t RlinkAddrMap::MaxNameLength() const void RlinkAddrMap::Print(std::ostream& os, int ind) const { - size_t maxlen = max(((size_t) 6), MaxNameLength()); + size_t maxlen = max(size_t(6), MaxNameLength()); RosFill bl(ind); - for (auto it=fAddrMap.begin(); it!=fAddrMap.end(); it++) { - os << bl << RosPrintf((it->second).c_str(), "-s",maxlen) - << " : " << RosPrintf(it->first, "$x0", 6) - << " " << RosPrintf(it->first, "o0", 6) << endl; + for (auto& o: fAddrMap) { + os << bl << RosPrintf(o.second.c_str(), "-s",maxlen) + << " : " << RosPrintf(o.first, "$x0", 6) + << " " << RosPrintf(o.first, "o0", 6) << endl; } return; diff --git a/tools/src/librlinktpp/RtclRlinkConnect.cpp b/tools/src/librlinktpp/RtclRlinkConnect.cpp index 2698b77d..26a37854 100644 --- a/tools/src/librlinktpp/RtclRlinkConnect.cpp +++ b/tools/src/librlinktpp/RtclRlinkConnect.cpp @@ -1,4 +1,4 @@ -// $Id: RtclRlinkConnect.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclRlinkConnect.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2011-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.6.2 use auto +// 2018-11-16 1070 1.6.2 use auto; use range loop // 2018-09-16 1047 1.6.1 coverity fixup (uninitialized scalar) // 2017-04-29 888 1.6 drop M_rawio; add M_rawread,M_rawrblk,M_rawwblk // 2017-04-22 883 1.5.2 M_amap: -testname opt addr check; add hasrbmon get @@ -540,10 +540,10 @@ int RtclRlinkConnect::M_amap(RtclArgs& args) } else { // amap RtclOPtr plist(Tcl_NewListObj(0, nullptr)); const auto amap = addrmap.Amap(); - for (auto it=amap.begin(); it!=amap.end(); it++) { + for (auto& o: amap) { Tcl_Obj* tpair[2]; - tpair[0] = Tcl_NewIntObj(it->first); - tpair[1] = Tcl_NewStringObj((it->second).c_str(),(it->second).length()); + tpair[0] = Tcl_NewIntObj(o.first); + tpair[1] = Tcl_NewStringObj(o.second.c_str(),o.second.length()); Tcl_ListObjAppendElement(nullptr, plist, Tcl_NewListObj(2, tpair)); } args.SetResult(plist); diff --git a/tools/src/librlinktpp/RtclRlinkServer.cpp b/tools/src/librlinktpp/RtclRlinkServer.cpp index a7afc259..36830537 100644 --- a/tools/src/librlinktpp/RtclRlinkServer.cpp +++ b/tools/src/librlinktpp/RtclRlinkServer.cpp @@ -1,4 +1,4 @@ -// $Id: RtclRlinkServer.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclRlinkServer.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.1.2 use auto +// 2018-11-16 1070 1.1.2 use auto; use range loop // 2017-04-02 865 1.1.1 M_dump: use GetArgsDump and Dump detail // 2015-04-04 662 1.1 add M_get, M_set; remove 'server -trace' // 2014-08-22 584 1.0.6 use nullptr @@ -106,9 +106,7 @@ RtclRlinkServer::RtclRlinkServer(Tcl_Interp* interp, const char* name) RtclRlinkServer::~RtclRlinkServer() { - for (auto it = fAttnHdl.begin(); it != fAttnHdl.end(); it++) { - delete (*it); - } + for (auto& po: fAttnHdl) delete po; } //------------------------------------------+----------------------------------- @@ -213,12 +211,12 @@ int RtclRlinkServer::M_attn(RtclArgs& args) if (!args.GetArg("mask", mask)) return kERR; if (!args.AllDone()) return kERR; RtclOPtr pres(Tcl_NewListObj(0,nullptr)); - for (auto it = fAttnHdl.begin(); it != fAttnHdl.end(); it++) { - if ((*it)->Mask() & mask) { + for (auto& po : fAttnHdl) { + if (po->Mask() & mask) { RtclOPtr pele(Tcl_NewListObj(0,nullptr)); Tcl_ListObjAppendElement(nullptr, pele, - Tcl_NewIntObj((*it)->Mask()) ); - Tcl_ListObjAppendElement(nullptr, pele, (*it)->Script() ); + Tcl_NewIntObj(po->Mask()) ); + Tcl_ListObjAppendElement(nullptr, pele, po->Script() ); Tcl_ListObjAppendElement(nullptr, pres, pele); } } @@ -230,10 +228,10 @@ int RtclRlinkServer::M_attn(RtclArgs& args) if (!args.GetArg("mask", mask)) return kERR; if (!args.AllDone()) return kERR; int nhdl = 0; - for (auto it = fAttnHdl.begin(); it != fAttnHdl.end(); it++) { - if ((*it)->Mask() & mask) { + for (auto& po: fAttnHdl) { + if (po->Mask() & mask) { nhdl += 1; - int rc = Tcl_EvalObjEx(interp, (*it)->Script(), TCL_EVAL_GLOBAL); + int rc = Tcl_EvalObjEx(interp, po->Script(), TCL_EVAL_GLOBAL); if (rc != kOK) return rc; } } @@ -244,8 +242,8 @@ int RtclRlinkServer::M_attn(RtclArgs& args) } else if (opt == "-list") { // attn -list if (!args.AllDone()) return kERR; vector vres; - for (auto it = fAttnHdl.begin(); it != fAttnHdl.end(); it++) { - vres.push_back((*it)->Mask()); + for (auto& po : fAttnHdl) { + vres.push_back(po->Mask()); } args.SetResult(Rtcl::NewListIntObj(vres)); } @@ -254,8 +252,8 @@ int RtclRlinkServer::M_attn(RtclArgs& args) if (!args.OptValid()) return kERR; if (!args.AllDone()) return kERR; uint16_t mask=0; - for (auto it = fAttnHdl.begin(); it != fAttnHdl.end(); it++) { - mask |= (*it)->Mask(); + for (auto& po: fAttnHdl) { + mask |= po->Mask(); } args.SetResult(mask); } diff --git a/tools/src/librtcltools/RtclContext.cpp b/tools/src/librtcltools/RtclContext.cpp index 0b37dc11..09b6cade 100644 --- a/tools/src/librtcltools/RtclContext.cpp +++ b/tools/src/librtcltools/RtclContext.cpp @@ -1,4 +1,4 @@ -// $Id: RtclContext.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclContext.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2011-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.0.5 use auto; use emplace,make_pair +// 2018-11-16 1070 1.0.5 use auto; use emplace,make_pair; use range loop // 2017-02-04 866 1.0.4 rename fMapContext -> fContextMap // 2013-02-03 481 1.0.3 use Rexception // 2013-01-12 474 1.0.2 add FindProxy() method @@ -128,9 +128,9 @@ void RtclContext::ListProxy(std::vector& list, const std::string& type) { list.clear(); - for (auto it = fSetProxy.begin(); it != fSetProxy.end(); it++) { - if (type.length() == 0 || (*it)->Type()==type) { - list.push_back(*it); + for (auto& po: fSetProxy) { + if (type.length() == 0 || po->Type()==type) { + list.push_back(po); } } return; @@ -142,10 +142,10 @@ void RtclContext::ListProxy(std::vector& list, RtclProxyBase* RtclContext::FindProxy(const std::string& type, const std::string& name) { - for (auto it = fSetProxy.begin(); it != fSetProxy.end(); it++) { - if (type.length() == 0 || (*it)->Type()==type) { - const char* cmdname = Tcl_GetCommandName(fInterp, (*it)->Token()); - if (name == cmdname) return *it; + for (auto& po: fSetProxy) { + if (type.length() == 0 || po->Type()==type) { + const char* cmdname = Tcl_GetCommandName(fInterp, po->Token()); + if (name == cmdname) return po; } } return 0; diff --git a/tools/src/librtcltools/RtclGetList.cpp b/tools/src/librtcltools/RtclGetList.cpp index c2e4b119..ec0cdc4d 100644 --- a/tools/src/librtcltools/RtclGetList.cpp +++ b/tools/src/librtcltools/RtclGetList.cpp @@ -1,4 +1,4 @@ -// $Id: RtclGetList.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclGetList.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.1.1 use auto; use emplace,make_pair +// 2018-11-16 1070 1.1.1 use auto; use emplace,make_pair; use range loop // 2015-01-08 631 1.1 add Clear(), add '?' (key list) and '*' (kv list) // 2014-08-22 584 1.0.1 use nullptr // 2013-02-12 487 1.0 Initial version @@ -54,9 +54,7 @@ RtclGetList::RtclGetList() RtclGetList::~RtclGetList() { - for (auto it=fMap.begin(); it != fMap.end(); it++) { - delete (it->second); - } + for (auto& o: fMap) delete o.second; } //------------------------------------------+----------------------------------- @@ -117,8 +115,8 @@ int RtclGetList::M_get(RtclArgs& args) Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(), "': must be ", nullptr); const char* delim = ""; - for (auto it1=fMap.begin(); it1!=fMap.end(); it1++) { - Tcl_AppendResult(interp, delim, it1->first.c_str(), nullptr); + for (auto& o: fMap) { + Tcl_AppendResult(interp, delim, o.first.c_str(), nullptr); delim = ","; } return TCL_ERROR; diff --git a/tools/src/librtcltools/RtclNameSet.cpp b/tools/src/librtcltools/RtclNameSet.cpp index 48181743..7576eed7 100644 --- a/tools/src/librtcltools/RtclNameSet.cpp +++ b/tools/src/librtcltools/RtclNameSet.cpp @@ -1,4 +1,4 @@ -// $Id: RtclNameSet.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclNameSet.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2011-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.1.2 use auto +// 2018-11-16 1070 1.1.2 use auto; use range loop // 2014-08-22 584 1.1.1 use nullptr // 2013-05-19 521 1.1 add CheckMatch() // 2013-02-03 481 1.0.1 use Rexception @@ -104,8 +104,8 @@ int RtclNameSet::CheckMatch(Tcl_Interp* interp, std::string& rval, Tcl_AppendResult(interp, "-E: bad option '", tval.c_str(), "': must be ", nullptr); const char* delim = ""; - for (auto it1=fSet.begin(); it1!=fSet.end(); it1++) { - Tcl_AppendResult(interp, delim, it1->c_str(), nullptr); + for (auto& o: fSet) { + Tcl_AppendResult(interp, delim, o.c_str(), nullptr); delim = ","; } } diff --git a/tools/src/librtcltools/RtclSetList.cpp b/tools/src/librtcltools/RtclSetList.cpp index 28c5bbae..41afe98b 100644 --- a/tools/src/librtcltools/RtclSetList.cpp +++ b/tools/src/librtcltools/RtclSetList.cpp @@ -1,4 +1,4 @@ -// $Id: RtclSetList.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclSetList.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.1.1 use auto; use emplace,make_pair +// 2018-11-16 1070 1.1.1 use auto; use emplace,make_pair; use range loop // 2015-01-08 631 1.1 add Clear(), add '?' (key list) // 2014-08-22 584 1.0.1 use nullptr // 2013-02-12 487 1.0 Initial version @@ -54,9 +54,7 @@ RtclSetList::RtclSetList() RtclSetList::~RtclSetList() { - for (auto it=fMap.begin(); it != fMap.end(); it++) { - delete (it->second); - } + for (auto& o: fMap) delete o.second; } //------------------------------------------+----------------------------------- @@ -107,8 +105,8 @@ int RtclSetList::M_set(RtclArgs& args) Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(), "': must be ", nullptr); const char* delim = ""; - for (auto it1=fMap.begin(); it1!=fMap.end(); it1++) { - Tcl_AppendResult(interp, delim, it1->first.c_str(), nullptr); + for (auto& o: fMap) { + Tcl_AppendResult(interp, delim, o.first.c_str(), nullptr); delim = ","; } return TCL_ERROR; diff --git a/tools/src/librtools/RparseUrl.cpp b/tools/src/librtools/RparseUrl.cpp index f9947ce7..73d311cd 100644 --- a/tools/src/librtools/RparseUrl.cpp +++ b/tools/src/librtools/RparseUrl.cpp @@ -1,4 +1,4 @@ -// $Id: RparseUrl.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RparseUrl.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.1.1 use auto; use emplace,make_pair +// 2018-11-16 1070 1.1.1 use auto; use emplace,make_pair; use range loop // 2017-04-15 875 1.1 add Set() with default scheme handling // 2015-06-04 686 1.0.2 Set(): add check that optlist is enclosed by '|' // 2013-02-23 492 1.0.1 add static FindScheme(); allow no or empty scheme @@ -194,9 +194,9 @@ void RparseUrl::Dump(std::ostream& os, int ind, const char* text) const os << bl << " fScheme: " << fScheme << endl; os << bl << " fPath: " << fPath << endl; os << bl << " fOptMap: " << endl; - for (auto it=fOptMap.begin(); it!=fOptMap.end(); it++) { - os << bl << " " << RosPrintf((it->first).c_str(), "-s",8) - << " : " << it->second << endl; + for (auto& o: fOptMap) { + os << bl << " " << RosPrintf(o.first.c_str(), "-s",8) + << " : " << o.second << endl; } return; } diff --git a/tools/src/librw11/Rw11Cpu.cpp b/tools/src/librw11/Rw11Cpu.cpp index ea79556e..3d39679d 100644 --- a/tools/src/librw11/Rw11Cpu.cpp +++ b/tools/src/librw11/Rw11Cpu.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11Cpu.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: Rw11Cpu.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.2.15 use auto; use emplace,make_pair +// 2018-11-16 1070 1.2.15 use auto; use emplace,make_pair; use range loop // 2018-09-23 1050 1.2.14 add HasPcnt() // 2018-09-22 1048 1.2.13 coverity fixup (drop unreachable code) // 2017-04-07 868 1.2.12 Dump(): add detail arg @@ -253,8 +253,8 @@ bool Rw11Cpu::TestCntl(const std::string& name) const void Rw11Cpu::ListCntl(std::vector& list) const { list.clear(); - for (auto it=fCntlMap.begin(); it!=fCntlMap.end(); it++) { - list.push_back((it->second)->Name()); + for (auto& o: fCntlMap) { + list.push_back(o.second->Name()); } return; } @@ -276,8 +276,8 @@ Rw11Cntl& Rw11Cpu::Cntl(const std::string& name) const void Rw11Cpu::Start() { - for (auto it=fCntlMap.begin(); it!=fCntlMap.end(); it++) { - Rw11Cntl& cntl(*(it->second)); + for (auto& o: fCntlMap) { + Rw11Cntl& cntl(*o.second); cntl.Probe(); if (cntl.ProbeStatus().Found() && cntl.Enable()) { cntl.Start(); @@ -882,9 +882,9 @@ void Rw11Cpu::Dump(std::ostream& os, int ind, const char* text, os << bl << " fCpuAct: " << fCpuAct << endl; os << bl << " fCpuStat: " << RosPrintf(fCpuStat,"$x0",4) << endl; os << bl << " fCntlMap: " << endl; - for (auto it=fCntlMap.begin(); it!=fCntlMap.end(); it++) { - os << bl << " " << RosPrintf((it->first).c_str(), "-s",8) - << " : " << it->second << endl; + for (auto& o: fCntlMap) { + os << bl << " " << RosPrintf(o.first.c_str(), "-s",8) + << " : " << o.second << endl; } fIAddrMap.Dump(os, ind+2, "fIAddrMap: ", detail-1); fRAddrMap.Dump(os, ind+2, "fRAddrMap: ", detail-1); diff --git a/tools/src/librw11/Rw11VirtTermTcp.cpp b/tools/src/librw11/Rw11VirtTermTcp.cpp index d3cc3e9f..c37aa67d 100644 --- a/tools/src/librw11/Rw11VirtTermTcp.cpp +++ b/tools/src/librw11/Rw11VirtTermTcp.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtTermTcp.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: Rw11VirtTermTcp.cpp 1068 2018-11-11 22:35:21Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-11-11 1066 1.0.8 coverity fixup (unchecked return value) // 2018-10-27 1059 1.0.7 coverity fixup (uncaught exception in dtor) // 2017-04-15 875 1.0.6 Open(): set default scheme // 2017-04-07 868 1.0.5 Dump(): add detail arg diff --git a/tools/src/librwxxtpp/RtclRw11Cpu.cpp b/tools/src/librwxxtpp/RtclRw11Cpu.cpp index b3ee6a17..df0b3d3a 100644 --- a/tools/src/librwxxtpp/RtclRw11Cpu.cpp +++ b/tools/src/librwxxtpp/RtclRw11Cpu.cpp @@ -1,4 +1,4 @@ -// $Id: RtclRw11Cpu.cpp 1066 2018-11-10 11:21:53Z mueller $ +// $Id: RtclRw11Cpu.cpp 1070 2018-11-17 09:48:04Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-11-09 1066 1.2.19 use auto; use emplace_back +// 2018-11-16 1070 1.2.19 use auto; use emplace_back; use range loop // 2018-09-23 1050 1.2.18 add HasPcnt() // 2018-09-21 1048 1.2.18 coverity fixup (uninitialized scalar) // 2017-04-22 883 1.2.17 M_(imap|rmap): -testname optional addr check @@ -225,10 +225,10 @@ int RtclRw11Cpu::M_imap(RtclArgs& args) } else { // imap RtclOPtr plist(Tcl_NewListObj(0, nullptr)); const auto amap = addrmap.Amap(); - for (auto it=amap.begin(); it!=amap.end(); it++) { + for (auto& o: amap) { Tcl_Obj* tpair[2]; - tpair[0] = Tcl_NewIntObj(it->first); - tpair[1] = Tcl_NewStringObj((it->second).c_str(),(it->second).length()); + tpair[0] = Tcl_NewIntObj(o.first); + tpair[1] = Tcl_NewStringObj(o.second.c_str(),o.second.length()); Tcl_ListObjAppendElement(nullptr, plist, Tcl_NewListObj(2, tpair)); } args.SetResult(plist); @@ -330,10 +330,10 @@ int RtclRw11Cpu::M_rmap(RtclArgs& args) } else { // rmap RtclOPtr plist(Tcl_NewListObj(0, nullptr)); const auto amap = lmap.Amap(); - for (auto it=amap.begin(); it!=amap.end(); it++) { + for (auto& o: amap) { Tcl_Obj* tpair[2]; - tpair[0] = Tcl_NewIntObj(it->first); - tpair[1] = Tcl_NewStringObj((it->second).c_str(),(it->second).length()); + tpair[0] = Tcl_NewIntObj(o.first); + tpair[1] = Tcl_NewStringObj(o.second.c_str(),o.second.length()); Tcl_ListObjAppendElement(nullptr, plist, Tcl_NewListObj(2, tpair)); } args.SetResult(plist); @@ -1162,17 +1162,15 @@ int RtclRw11Cpu::M_ldasm(RtclArgs& args) dot = 0; RerrMsg emsg; - for (auto it=cmap.begin(); it!=cmap.end(); it++) { - //cout << "+++2 mem[" << RosPrintf(it->first, "o0", 6) - // << "]=" << RosPrintf(it->second, "o0", 6) << endl; - if (dot != it->first || block.size() >= Connect().BlockSizeMax()) { + for (auto& o: cmap) { + if (dot != o.first || block.size() >= Connect().BlockSizeMax()) { if (block.size()) { if (!Obj().MemWrite(base, block, emsg)) return args.Quit(emsg); block.clear(); } - base = dot = it->first; + base = dot = o.first; } - block.push_back(it->second); + block.push_back(o.second); dot += 2; }