From e329fa3296bf587a1c2159a48da9d826f1310afc Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 24 Apr 2022 12:50:40 -0500 Subject: [PATCH] CA Client: Protect against epicsTime::strftime() throwing libCa shouldn't cause an application to abort with an uncaught exception on a machine that has timezone problems just because we can't convert the current time into a string. --- modules/ca/src/client/ca_client_context.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/ca/src/client/ca_client_context.cpp b/modules/ca/src/client/ca_client_context.cpp index 671d1210b..1e830fd08 100644 --- a/modules/ca/src/client/ca_client_context.cpp +++ b/modules/ca/src/client/ca_client_context.cpp @@ -392,9 +392,19 @@ void ca_client_context :: vSignal ( } epicsTime current = epicsTime::getCurrent (); - char date[64]; - current.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f"); - this->printFormated ( " Current Time: %s\n", date ); + try { + char date[64]; + current.strftime ( date, sizeof ( date ), "%a %b %d %Y %H:%M:%S.%f"); + this->printFormated ( " Current Time: %s\n", date ); + } + catch ( std::exception & except ) { + errlogPrintf ( + "CA client library thread \"%s\" caught C++ exception \"%s\"\n", + epicsThreadGetNameSelf (), except.what () ); + epicsTimeStamp now = current; + this->printFormated ( " Current Time: %u.%u\n", + now.secPastEpoch, now.nsec ); + } /* * Terminate execution if unsuccessful