LP#1243841 - Quiet additional Make warnings and some code cleanup.
[opensrf-equinox.git] / src / libopensrf / osrf_cache.c
index dd489e1..08ac596 100644 (file)
@@ -14,6 +14,7 @@ GNU General Public License for more details.
 */
 
 #include <opensrf/osrf_cache.h>
+#include <ctype.h>
 
 #define MAX_KEY_LEN 250
 
@@ -59,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) || 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';
@@ -138,7 +141,9 @@ int osrfCacheRemove( const char* key, ... ) {
        memcached_return rc;
        if( key ) {
                VA_LIST_TO_STRING(key);
-               rc = memcached_delete(_osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+               char* clean_key = _clean_key( VA_BUF );
+               rc = memcached_delete(_osrfCache, clean_key, strlen(clean_key), 0 );
+               free(clean_key);
                if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) {
                        osrfLogDebug(OSRF_LOG_MARK, "Failed to delete key [%s] - %s",
                                VA_BUF, memcached_strerror(_osrfCache, rc));