From e6dab90bf461fa516765f561748beaff6c7f9967 Mon Sep 17 00:00:00 2001 From: Emilio Perez Date: Thu, 9 Mar 2023 16:05:07 +0000 Subject: [PATCH] Make adding an identical error symbol not fail A test case was also added which test that adding an error symbol with same error code and message as one added before will not fail --- modules/libcom/src/error/errSymLib.c | 7 ++++++- modules/libcom/test/epicsErrlogTest.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/libcom/src/error/errSymLib.c b/modules/libcom/src/error/errSymLib.c index eea7b4b2f..d22d178cb 100644 --- a/modules/libcom/src/error/errSymLib.c +++ b/modules/libcom/src/error/errSymLib.c @@ -105,7 +105,12 @@ int errSymbolAdd(long errNum, const char *name) /* search for last node (NULL) of hashnode linked list */ while (pNextNode) { if (pNextNode->errNum == errNum) { - return S_err_codeExists; + if(strcmp(name, pNextNode->message)) { + return S_err_codeExists; + } + else { + return 0; + } } phashnode = &pNextNode->hashnode; pNextNode = *phashnode; diff --git a/modules/libcom/test/epicsErrlogTest.c b/modules/libcom/test/epicsErrlogTest.c index 59a149cb5..3638da34d 100644 --- a/modules/libcom/test/epicsErrlogTest.c +++ b/modules/libcom/test/epicsErrlogTest.c @@ -238,13 +238,21 @@ static void testAddingExistingErrorSymbol() "Adding an error symbol with an existing error code should fail"); } +static void testAddingExistingErrorSymbolWithSameMessage() +{ + long invented_code = (0x7999 << 16) | 0x9997; + errSymbolAdd(invented_code, "Invented Error Message"); + testOk(!errSymbolAdd(invented_code, "Invented Error Message"), + "Adding identical error symbol shouldn't fail"); +} + MAIN(epicsErrlogTest) { size_t mlen, i, N; char msg[256]; clientPvt pvt, pvt2; - testPlan(53); + testPlan(54); testANSIStrip(); @@ -460,6 +468,7 @@ MAIN(epicsErrlogTest) testAddingErrorSymbol(); testAddingInvalidErrorSymbol(); testAddingExistingErrorSymbol(); + testAddingExistingErrorSymbolWithSameMessage(); return testDone(); }