Hi Srinivas, Ack
Thanks Lennart > -----Original Message----- > From: Srinivas [mailto:[email protected]] > Sent: den 23 november 2017 11:25 > To: Vu Minh Nguyen <[email protected]>; Lennart Lund > <[email protected]> > Cc: [email protected]; Srinivas > <[email protected]> > Subject: [PATCH 1/1] log: fixed most of the Cppcheck warnings in apiTest and > tools dir [#2439] > > --- > src/log/apitest/imm_tstutil.c | 3 +-- > src/log/apitest/logtest.c | 6 ++---- > src/log/apitest/logtestfr.c | 6 ++---- > src/log/apitest/saflogtest.c | 12 +++++------- > src/log/apitest/tet_LogOiOps.c | 2 +- > src/log/apitest/tet_Log_recov.c | 6 ++---- > src/log/apitest/tet_multiple_thread.c | 4 ++-- > src/log/apitest/tet_saLogStreamOpen_2.c | 4 ++-- > src/log/tools/saf_logger.c | 3 +++ > 9 files changed, 20 insertions(+), 26 deletions(-) > > diff --git a/src/log/apitest/imm_tstutil.c b/src/log/apitest/imm_tstutil.c > index f7849cd..7a555d6 100644 > --- a/src/log/apitest/imm_tstutil.c > +++ b/src/log/apitest/imm_tstutil.c > @@ -94,10 +94,9 @@ bool > get_multivalue_type_string_from_imm(SaImmHandleT *omHandle, > NULL; /* NULL terminated array */ > > /* Save values */ > - void *value = NULL; > for (uint32_t i = 0; i < attribute->attrValuesNumber; > i++) { > - value = attribute->attrValues[i]; > + void *value = attribute->attrValues[i]; > str_array[i] = *(char **)value; > } > } > diff --git a/src/log/apitest/logtest.c b/src/log/apitest/logtest.c > index 02d5d7d..afa1fcf 100644 > --- a/src/log/apitest/logtest.c > +++ b/src/log/apitest/logtest.c > @@ -111,7 +111,6 @@ void init_logrootpath(void) > const char logRootDirectory_name[] = "logRootDirectory"; > SaImmAttrNameT attributeNames[2] = {(char > *)logRootDirectory_name, > NULL}; > - void *value; > > saAisNameLend(config, &objectName); > /* NOTE: immutil init osaf_assert if error */ > @@ -123,7 +122,7 @@ void init_logrootpath(void) > attributeNames, &attributes); > if (ais_rc == SA_AIS_OK) { > attribute = attributes[0]; > - value = attribute->attrValues[0]; > + void *value = attribute->attrValues[0]; > strncpy(log_root_path, *((char **)value), PATH_MAX); > } else { > /* We didn't get a root path from IMM. Use default */ > @@ -147,7 +146,6 @@ int get_attr_value(SaNameT *inObjName, char > *inAttr, void *outValue) > SaImmAttrValuesT_2 **attributes; > SaAisErrorT ais_rc = SA_AIS_OK; > SaImmAttrNameT attributeNames[2] = {inAttr, NULL}; > - void *value = NULL; > int rc = 0; > > /* NOTE: immutil init osaf_assert if error */ > @@ -160,7 +158,7 @@ int get_attr_value(SaNameT *inObjName, char > *inAttr, void *outValue) > if (ais_rc == SA_AIS_OK) { > attribute = attributes[0]; > if ((attribute != NULL) && (attribute->attrValuesNumber != > 0)) { > - value = attribute->attrValues[0]; > + void *value = attribute->attrValues[0]; > switch (attribute->attrValueType) { > case SA_IMM_ATTR_SAINT32T: > *((SaInt32T *)outValue) = *(SaInt32T > *)value; > diff --git a/src/log/apitest/logtestfr.c b/src/log/apitest/logtestfr.c > index 59c3175..b2ef30b 100644 > --- a/src/log/apitest/logtestfr.c > +++ b/src/log/apitest/logtestfr.c > @@ -191,7 +191,6 @@ void get_logRootDirectory(char *path_str) > const char logRootDirectory_name[] = "logRootDirectory"; > SaImmAttrNameT attributeNames[2] = {(char > *)logRootDirectory_name, > NULL}; > - void *value; > > /* NOTE: immutil init osaf_assert if error */ > (void)immutil_saImmOmInitialize(&omHandle, NULL, > &kImmVersion); > @@ -202,7 +201,7 @@ void get_logRootDirectory(char *path_str) > attributeNames, &attributes); > if (ais_rc == SA_AIS_OK) { > attribute = attributes[0]; > - value = attribute->attrValues[0]; > + void *value = attribute->attrValues[0]; > strncpy(path_str, *((char **)value), PATH_MAX); > } else { > /* We didn't get a root path from IMM. Use default */ > @@ -750,11 +749,10 @@ static void usage(void) > int main(int argc, char **argv) > { > int rc = 0; > - int opt_val = 0; > > /* Handle options */ > while (1) { > - opt_val = getopt(argc, argv, "vsh"); > + int opt_val = getopt(argc, argv, "vsh"); > if (opt_val < 0) > break; > switch (opt_val) { > diff --git a/src/log/apitest/saflogtest.c b/src/log/apitest/saflogtest.c > index e6db5e1..8574c4f 100644 > --- a/src/log/apitest/saflogtest.c > +++ b/src/log/apitest/saflogtest.c > @@ -306,12 +306,9 @@ static void create_log_record(SaLogRecordT > *logRecord, > } > > /* Create body of log record (if any) */ > - int sz; > - char *logBuf = NULL; > - > if (log_message != NULL) { > - sz = strlen(log_message) + 1; > - logBuf = malloc( > + int sz = strlen(log_message) + 1; > + char *logBuf = malloc( > sz + 64); /* add space for index/id in periodic writes */ > strcpy(logBuf, log_message); > logBuffer->logBufSize = sz; > @@ -356,7 +353,7 @@ static void free_logFileCreateAttributes( > > int main(int argc, char *argv[]) > { > - int c, i; > + int i; > // SaNameT logStreamName; > SaLogStreamOpenFlagsT logStreamOpenFlags = 0; > SaNameT logSvcUsrName; > @@ -413,7 +410,8 @@ int main(int argc, char *argv[]) > logSvcUsrName.length = strlen((char *)logSvcUsrName.value); > > while (1) { > - c = getopt_long(argc, argv, "eohklnya:b:s:i:c:", long_options, > + int c = getopt_long(argc, argv, "eohklnya:b:s:i:c:", > + long_options, > NULL); > if (c == -1) { > break; > diff --git a/src/log/apitest/tet_LogOiOps.c b/src/log/apitest/tet_LogOiOps.c > index 0ee8078..a1c64a1 100644 > --- a/src/log/apitest/tet_LogOiOps.c > +++ b/src/log/apitest/tet_LogOiOps.c > @@ -3861,7 +3861,6 @@ void verTimeZoneMilliInDefaultLogFileFmt(void) > // Enable time-zone and millisecond token - @Cz @Ck > const char *modLogStrFileFmt = > "@Cr @Ch:@Cn:@Cs @Cm/@Cd/@CY @Cz @Ck @Sv @Sl @Cb"; > - const char *app_stream_name = "safLgStr=verDefaultLogFileFmt"; > > // Get current value of the attribute > get_attr_value(&configurationObject, "logStreamFileFormat", > @@ -3874,6 +3873,7 @@ void verTimeZoneMilliInDefaultLogFileFmt(void) > > rc = systemCall(command); > if (rc == 0) { > + const char *app_stream_name = > "safLgStr=verDefaultLogFileFmt"; > // Create app stream and write log record to it by saflogger > sprintf(command, "saflogger -a %s", app_stream_name); > rc = systemCall(command); > diff --git a/src/log/apitest/tet_Log_recov.c b/src/log/apitest/tet_Log_recov.c > index 2a88d39..a04a545 100644 > --- a/src/log/apitest/tet_Log_recov.c > +++ b/src/log/apitest/tet_Log_recov.c > @@ -388,7 +388,6 @@ static int > tst_StreamOpen_app_logtest_sc(SaLogHandleT logHandle, > int trycnt = 0; > SaAisErrorT ais_rc = SA_AIS_OK; > int rc = 0; > - int n; > int i; > char data[255]; > > @@ -397,7 +396,7 @@ static int > tst_StreamOpen_app_logtest_sc(SaLogHandleT logHandle, > /* Prepare stream name and attributes for the stream to be > * opened */ > SaNameT stream_name; > - n = sprintf(data, "safLgStr=%s_%d", STREAM_NAME_9, i + 1); > + int n = sprintf(data, "safLgStr=%s_%d", STREAM_NAME_9, i + > 1); > saAisNameLend(data, &stream_name); > if (n < 0) { > fprintf(stderr, "\t%s [%d] sprintf Fail\n", > @@ -501,7 +500,6 @@ static void tst_max_logrec_create(char *logrec_str, > uint32_t lsize, > { > int n; > size_t fill_size; > - char *ptr_fill_start = NULL; > > /* Create information part of message */ > n = snprintf(logrec_str, lsize, "%s size %d ", log_msg, lsize); > @@ -514,7 +512,7 @@ static void tst_max_logrec_create(char *logrec_str, > uint32_t lsize, > > /* Fill message with dummy char to make it the wanted size */ > if (fill_size > 0) { > - ptr_fill_start = logrec_str + n; > + char *ptr_fill_start = logrec_str + n; > memset(ptr_fill_start, 'f', fill_size); > logrec_str[lsize - 1] = '\0'; > } > diff --git a/src/log/apitest/tet_multiple_thread.c > b/src/log/apitest/tet_multiple_thread.c > index a41185e..8e4f415 100644 > --- a/src/log/apitest/tet_multiple_thread.c > +++ b/src/log/apitest/tet_multiple_thread.c > @@ -111,7 +111,7 @@ done: > > void delete_and_access_log_stream_on_multiple_threads(void) > { > - int i, errno, nThreads = 5; > + int i, nThreads = 5; > SaAisErrorT rc_me = SA_AIS_OK; > pthread_t threads[nThreads]; > pthread_t threads2[nThreads]; > @@ -271,7 +271,7 @@ done: > > void delete_and_access_log_handle_on_multiple_threads(void) > { > - int i, errno, nThreads = 5; > + int i, nThreads = 5; > SaAisErrorT rc_me = SA_AIS_OK; > pthread_t threads[nThreads]; > pthread_t threads2[nThreads]; > diff --git a/src/log/apitest/tet_saLogStreamOpen_2.c > b/src/log/apitest/tet_saLogStreamOpen_2.c > index 779cbd5..6992392 100644 > --- a/src/log/apitest/tet_saLogStreamOpen_2.c > +++ b/src/log/apitest/tet_saLogStreamOpen_2.c > @@ -944,7 +944,7 @@ void saLogMultipleInitialize(void) > */ > void saLogMultiThreadMultiInit(void) > { > - int ret, i, errno, nThreads = 50; > + int i, errno, nThreads = 50; > SaAisErrorT rt[nThreads], rc = SA_AIS_OK; > pthread_t threads[nThreads]; > struct timespec timeout_t; > @@ -968,7 +968,7 @@ void saLogMultiThreadMultiInit(void) > > /* Wait for threads terminated with timeout */ > for (i = 0; i < nThreads; i++) { > - ret = pthread_timedjoin_np(threads[i], NULL, &timeout_t); > + int ret = pthread_timedjoin_np(threads[i], NULL, > &timeout_t); > if (ret != 0) { > fprintf(stderr, " Thread %d join error: %s\n", > i, strerror(ret)); > diff --git a/src/log/tools/saf_logger.c b/src/log/tools/saf_logger.c > index 05b1fcf..dd20fa1 100644 > --- a/src/log/tools/saf_logger.c > +++ b/src/log/tools/saf_logger.c > @@ -556,6 +556,9 @@ int main(int argc, char *argv[]) > error = saLogFinalize(logHandle); > } > > + if (appLogFileCreateAttributes.logFileName != NULL) > + > free(appLogFileCreateAttributes.logFileName); > + > if (SA_AIS_OK != error) { > if (wait_time) > fprintf(stderr, "Waited for %u seconds.\n", > -- > 2.7.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
