From 35c7bb1b81bd41d99ad0a0756bf669a13e6ef63b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 7 Nov 2017 15:58:05 -0500 Subject: [PATCH] LP#1243841 - Quiet additional Make warnings and some code cleanup. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We make the following warnings go away: osrf_legacy_json.c:607:6: warning: variable ‘fourth_dash’ set but not used [-Wunused-but-set-variable] osrf_legacy_json.c:836:5: warning: passing argument 3 of ‘makeNode’ discards ‘const’ qualifier from pointer target type [enabled by default] utils.c:133:2: warning: format not a string literal and no format arguments [-Wformat-security] We also cleanup the while block nested in a do while block around line 63 of osrf_cache.c to be more readable by adding braces and breaking it across 3 lines. Signed-off-by: Jason Stephenson Signed-off-by: Galen Charlton --- src/libopensrf/osrf_cache.c | 4 +++- src/libopensrf/osrf_legacy_json.c | 10 ++++------ src/libopensrf/utils.c | 9 ++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c index b9ef6e9..08ac596 100644 --- a/src/libopensrf/osrf_cache.c +++ b/src/libopensrf/osrf_cache.c @@ -60,7 +60,9 @@ char* _clean_key( const char* key ) { char* clean_key = (char*)strdup(key); char* d = clean_key; char* s = clean_key; - do while( (isspace(*s) || ((*s != '\0') && iscntrl(*s))) ) s++; while( (*d++ = *s++) ); + do { + while(isspace(*s) || ((*s != '\0') && iscntrl(*s))) s++; + } while((*d++ = *s++)); if (strlen(clean_key) > MAX_KEY_LEN) { char *hashed = md5sum(clean_key); clean_key[0] = '\0'; diff --git a/src/libopensrf/osrf_legacy_json.c b/src/libopensrf/osrf_legacy_json.c index cd43d13..1ed4555 100644 --- a/src/libopensrf/osrf_legacy_json.c +++ b/src/libopensrf/osrf_legacy_json.c @@ -603,8 +603,6 @@ int json_eat_comment(char* string, unsigned long* index, char** buffer, int pars int first_dash = 0; int second_dash = 0; - int third_dash = 0; - int fourth_dash = 0; int in_hint = 0; int done = 0; @@ -619,9 +617,7 @@ int json_eat_comment(char* string, unsigned long* index, char** buffer, int pars case '-': on_star = 0; - if(third_dash) fourth_dash = 1; - else if(in_hint) third_dash = 1; - else if(first_dash) second_dash = 1; + if(first_dash) second_dash = 1; else first_dash = 1; break; @@ -833,7 +829,9 @@ jsonObjectNode* jsonObjectIteratorNext( jsonObjectIterator* itr ) { itr->done = 1; return NULL; } - itr->current = makeNode(next, itr->iterator->index, itr->iterator->key); + /* Lp 1243841: Remove compiler const warning. */ + char *k = (char *) itr->iterator->key; + itr->current = makeNode(next, itr->iterator->index, k); return itr->current; } diff --git a/src/libopensrf/utils.c b/src/libopensrf/utils.c index ff0afc3..2698f1d 100644 --- a/src/libopensrf/utils.c +++ b/src/libopensrf/utils.c @@ -113,8 +113,7 @@ int init_proc_title( int argc, char* argv[] ) { provide values to be formatted and inserted into the format string. @return Length of the resulting string (or what the length would be if the receiving buffer were big enough to hold it), or -1 in case of an encoding - error. Note: because some older versions of snprintf() don't work correctly, - this function may return -1 if the string is truncated for lack of space. + error. Formats a string as directed, and uses it to replace the name of the currently running executable. This replacement string is what will @@ -130,7 +129,11 @@ int init_proc_title( int argc, char* argv[] ) { int set_proc_title( const char* format, ... ) { VA_LIST_TO_STRING(format); osrf_clearbuf( *(global_argv), global_argv_size); - return snprintf( *(global_argv), global_argv_size, VA_BUF ); + (void) strncpy( *(global_argv), VA_BUF, global_argv_size - 1 ); + if (strlen(VA_BUF) >= global_argv_size) { + *(global_argv)[global_argv_size - 1] = '\0'; + } + return (strlen(VA_BUF) > strlen(*(global_argv))) ? strlen(VA_BUF) : strlen(*(global_argv)); } /** -- 2.43.2