From 76244111d1710f2edcef33c0e456d767317b4062 Mon Sep 17 00:00:00 2001 From: "Walter F.J. Mueller" Date: Sun, 30 Apr 2017 15:17:41 +0200 Subject: [PATCH] BUGFIXes for backend - RlinkPort: BUGFIX: RawRead(): proper irc for exactsize=false - Rexception: BUGFIX: add fErrtxt for proper what() return --- tools/src/librlink/RlinkPort.cpp | 5 +++-- tools/src/librtools/Rexception.cpp | 27 ++++++++++++++++++--------- tools/src/librtools/Rexception.hpp | 10 ++++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tools/src/librlink/RlinkPort.cpp b/tools/src/librlink/RlinkPort.cpp index bf86774a..5ee81222 100644 --- a/tools/src/librlink/RlinkPort.cpp +++ b/tools/src/librlink/RlinkPort.cpp @@ -1,4 +1,4 @@ -// $Id: RlinkPort.cpp 887 2017-04-28 19:32:52Z mueller $ +// $Id: RlinkPort.cpp 888 2017-04-30 13:06:51Z mueller $ // // Copyright 2011-2017 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2017-04-29 888 1.4.2 BUGFIX: RawRead(): proper irc for exactsize=false // 2017-04-07 868 1.4.1 Dump(): add detail arg // 2017-02-19 853 1.4 use Rtime, drop TimeOfDayAsDouble // 2015-04-11 666 1.3 add fXon, XonEnable() @@ -274,8 +275,8 @@ int RlinkPort::RawRead(uint8_t* buf, size_t size, bool exactsize, tnow.GetClock(CLOCK_MONOTONIC); tused = tnow - tbeg; if (irc <= 0) return irc; - if (!exactsize) break; ndone += irc; + if (!exactsize) break; } return (int)ndone; diff --git a/tools/src/librtools/Rexception.cpp b/tools/src/librtools/Rexception.cpp index eac7be63..8e3e3711 100644 --- a/tools/src/librtools/Rexception.cpp +++ b/tools/src/librtools/Rexception.cpp @@ -1,6 +1,6 @@ -// $Id: Rexception.cpp 887 2017-04-28 19:32:52Z mueller $ +// $Id: Rexception.cpp 888 2017-04-30 13:06:51Z mueller $ // -// Copyright 2013-2014 by Walter F.J. Mueller +// Copyright 2013-2017 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 +// 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 // --------------------------------------------------------------------------- @@ -38,21 +39,25 @@ namespace Retro { //! Default constructor Rexception::Rexception() - : fErrmsg() -{} + : fErrmsg(), + fErrtxt() +{ +} //------------------------------------------+----------------------------------- //! FIXME_docs Rexception::Rexception(const RerrMsg& errmsg) - : fErrmsg(errmsg) + : fErrmsg(errmsg), + fErrtxt(fErrmsg.Message()) {} //------------------------------------------+----------------------------------- //! FIXME_docs Rexception::Rexception(const std::string& meth, const std::string& text) - : fErrmsg(meth,text) + : fErrmsg(meth,text), + fErrtxt(fErrmsg.Message()) {} //------------------------------------------+----------------------------------- @@ -60,7 +65,8 @@ Rexception::Rexception(const std::string& meth, const std::string& text) Rexception::Rexception(const std::string& meth, const std::string& text, int errnum) - : fErrmsg(meth,text,errnum) + : fErrmsg(meth,text,errnum), + fErrtxt(fErrmsg.Message()) {} //------------------------------------------+----------------------------------- @@ -68,7 +74,8 @@ Rexception::Rexception(const std::string& meth, const std::string& text, Rexception::Rexception(const std::string& meth, const std::string& text, const RerrMsg& errmsg) - : fErrmsg(meth,text+errmsg.Message()) + : fErrmsg(meth,text+errmsg.Message()), + fErrtxt(fErrmsg.Message()) {} //------------------------------------------+----------------------------------- @@ -82,7 +89,9 @@ Rexception::~Rexception() throw() const char* Rexception::what() const throw() { - return fErrmsg.Message().c_str(); + // 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. + return fErrtxt.c_str(); } } // end namespace Retro diff --git a/tools/src/librtools/Rexception.hpp b/tools/src/librtools/Rexception.hpp index 0a5a87df..85c60058 100644 --- a/tools/src/librtools/Rexception.hpp +++ b/tools/src/librtools/Rexception.hpp @@ -1,6 +1,6 @@ -// $Id: Rexception.hpp 887 2017-04-28 19:32:52Z mueller $ +// $Id: Rexception.hpp 888 2017-04-30 13:06:51Z mueller $ // -// Copyright 2013-2014 by Walter F.J. Mueller +// Copyright 2013-2017 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 +// 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 // 2013-01-12 474 1.0 Initial version @@ -46,11 +47,12 @@ namespace Retro { const std::string& text, const RerrMsg& errmsg); ~Rexception() throw(); - const char* what() const throw(); + virtual const char* what() const throw(); const RerrMsg& ErrMsg() const; protected: - RerrMsg fErrmsg; //!< message object + RerrMsg fErrmsg; //!< message object + std::string fErrtxt; //!< message text (for what()) }; } // end namespace Retro