[PATCH] [COMMON] API Code Hygiene improvements - Common


Adrienne Ambrose <AAmbrose@...>
 

This is requested code hygiene improvements requested by Damian for re-submission from original commit.

This would be covered under general regression testing.

 

 

From 09adac845a2742c5571ccf1f304d26e5e4ef5722 Mon Sep 17 00:00:00 2001

From: A Ambrose <aambrose@...>

Date: Thu, 29 May 2014 18:01:44 +0100

Subject: [PATCH] Api Code hygiene improvements - Common

property.c/wMessageStats.c [OMAMA-240]

 

Signed-off-by: A Ambrose <aambrose@...>

---

common/c_cpp/src/c/property.c      | 11 +++++++----

common/c_cpp/src/c/wMessageStats.c | 26 +++++++++++---------------

2 files changed, 18 insertions(+), 19 deletions(-)

 

diff --git a/common/c_cpp/src/c/property.c b/common/c_cpp/src/c/property.c

index 779ae63..08772c6 100644

--- a/common/c_cpp/src/c/property.c

+++ b/common/c_cpp/src/c/property.c

@@ -77,8 +77,9 @@ properties_Load( const char* path, const char* fileName )

     this->mTable = wtable_create( "", 10 );

-    if( this->mTable == NULL && this->mKeys != NULL )

+    if(this->mTable == NULL)

     {

+        free (this);

         return NULL;

     }

@@ -224,9 +225,9 @@ properties_Create( void )

         return NULL;

     }

     this->mTable = wtable_create( "", 10 );

-    if( this->mTable == NULL && this->mKeys != NULL )

+    if(this->mTable == NULL)

    {

-        free( (void* )this->mKeys );

+        free(this);

         return NULL;

     }

@@ -496,11 +497,13 @@ properties_AddEscapes (const char* src, const char chars[], int num)

{

    int i = 0, j = 0, retIdx = 0, matches = 0;

    char* retStr;

-   int strln = strlen (src);

+   int strln = 0;

    if (!src)

       return NULL;

+   strln = strlen (src);

+

    /* First need to number chars to escape to malloc the correct string len */

    for (;i < strln; i++)

    {

diff --git a/common/c_cpp/src/c/wMessageStats.c b/common/c_cpp/src/c/wMessageStats.c

index 5d1923a..3533dde 100644

--- a/common/c_cpp/src/c/wMessageStats.c

+++ b/common/c_cpp/src/c/wMessageStats.c

@@ -240,7 +240,7 @@ int createStatisticsCache(statsCache** sCache,int numMsgCategories,

     statsCache* mysCache = (statsCache*)calloc(1,sizeof(statsCache));

     if(!mysCache)

     {

-        mysCacheStatus = STATS_NO_MEMORY;

+        return STATS_NO_MEMORY;

     }

     mysCache->mNumMsg = numMsgCategories;

     mysCache->mHeader = header;

@@ -284,22 +284,19 @@ int createStatisticsCache(statsCache** sCache,int numMsgCategories,

         /* Global statistics */

         const char* dummySymbol = "Global";

         mysCache->mPData =(perfData*)calloc(1,sizeof(perfData));

-        if(!mysCache)

+        if(!mysCache->mPData)

         {

             return STATS_NO_MEMORY;

         }

-    initPerfData(mysCache->mPData, outfile, dummySymbol);

+        initPerfData(mysCache->mPData, outfile, dummySymbol);

-        if(mysCache->mPData)

+        if(mysCache->mHeader == 1 && mysCache->mOutfile == stdout)

         {

-            if(mysCache->mHeader == 1 && mysCache->mOutfile == stdout)

-            {

-                fprintf(mysCache->mOutfile, "%s", opHeaderPeriod);

-                mysCache->mHeader=0;

-            }

-

-            *sCache = mysCache;

+            fprintf(mysCache->mOutfile, opHeaderPeriod);

+            mysCache->mHeader=0;

         }

+

+        *sCache = mysCache;

     }

     return STATS_OK;

}

@@ -598,10 +595,9 @@ latencyVals calcLatency1TimeStamp(const char* timeStamp,

     int mins=0;

#endif

-    lenTimeFormat = strlen(timeFormat);

-    lenTimeStamp = strlen(timeStamp);

-    if ((timeStamp == NULL) || (timeFormat== NULL)

-        || (lenTimeFormat == 0) || (lenTimeStamp == 0))

+    lenTimeFormat = ((NULL == timeFormat) ? 0 : strlen(timeFormat));

+    lenTimeStamp = ((NULL == timeStamp) ? 0 : strlen(timeStamp));

+    if ((lenTimeFormat == 0) || (lenTimeStamp == 0))

     {

      fprintf(stderr,"Error - calcLatency\n");

       return noLatVals;

--

1.8.3.1

 


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of IntercontinentalExchange Group, Inc. (ICE), NYSE Euronext or any of their subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.

Join Openmama-dev@lists.openmama.org to automatically receive all group messages.