libs/lmo: fix typo in previous commit
[project/luci.git] / libs / lmo / src / lmo_core.c
index 17467f2..6a9623a 100644 (file)
@@ -207,15 +207,20 @@ int lmo_lookup(lmo_archive_t *ar, const char *key, char *dest, int len)
 {
        uint32_t look_key = sfh_hash(key, strlen(key));
        int copy_len = -1;
+       lmo_entry_t *entry;
 
-       lmo_entry_t *entry = ar->index;
+       if( !ar )
+               return copy_len;
+
+       entry = ar->index;
 
        while( entry != NULL )
        {
                if( entry->key_id == look_key )
                {
-                       copy_len = (len > entry->length) ? entry->length : len;
+                       copy_len = ((len - 1) > entry->length) ? entry->length : (len - 1);
                        memcpy(dest, &ar->mmap[entry->offset], copy_len);
+                       dest[copy_len] = '\0';
 
                        break;
                }