libs/lmo: fix typo in previous commit
[project/luci.git] / libs / lmo / src / lmo_core.c
index cd117be..6a9623a 100644 (file)
@@ -71,7 +71,7 @@ lmo_archive_t * lmo_open(const char *file)
                goto cleanup;
        }
 
-       if( lseek(in, (off_t)(-sizeof(uint32_t)), SEEK_END) == -1 )
+       if( lseek(in, -sizeof(uint32_t), SEEK_END) == -1 )
        {
                error("Can not seek to eof", 1);
                goto cleanup;
@@ -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;
                }