libs/lmo: fix typo in previous commit
[project/luci.git] / libs / lmo / src / lmo_core.c
index 0754d0d..6a9623a 100644 (file)
@@ -22,13 +22,10 @@ extern char _lmo_error[1024];
 
 static int lmo_read32( int fd, uint32_t *val )
 {
-       uint8_t buffer[5];
-
-       if( read(fd, buffer, 4) < 4 )
+       if( read(fd, val, 4) < 4 )
                return -1;
 
-       buffer[4] = 0;
-       *val = ntohl(*((uint32_t *) buffer));
+       *val = ntohl(*val);
 
        return 4;
 }
@@ -86,7 +83,7 @@ lmo_archive_t * lmo_open(const char *file)
                goto cleanup;
        }
 
-       if( lseek(in, idx_offset, SEEK_SET) == -1 )
+       if( lseek(in, (off_t)idx_offset, SEEK_SET) == -1 )
        {
                error("Can not seek to index offset", 1);
                goto cleanup;
@@ -210,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;
+
+       if( !ar )
+               return copy_len;
 
-       lmo_entry_t *entry = ar->index;
+       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;
                }