LP#1243841 - Quiet additional Make warnings and some code cleanup.
authorJason Stephenson <jason@sigio.com>
Tue, 7 Nov 2017 20:58:05 +0000 (15:58 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 7 May 2018 19:55:48 +0000 (15:55 -0400)
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 <jason@sigio.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

src/libopensrf/osrf_cache.c
src/libopensrf/osrf_legacy_json.c
src/libopensrf/utils.c

index b9ef6e9..08ac596 100644 (file)
@@ -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';
index cd43d13..1ed4555 100644 (file)
@@ -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;
 }
 
index ff0afc3..2698f1d 100644 (file)
@@ -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));
 }
 
 /**