shithub: lwext4

Download patch

ref: b6a7544b8c5b52b1d13f3b9c7c94cdabb6bf5ed1
parent: 1f5edc9325fc4427ebf3de5a4b1a21e38e6cc211
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue May 20 17:34:12 EDT 2014

Pedanitic warning check fixes. Pointer arithmetic, anonymus unions etc

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,7 @@
 cmake_minimum_required(VERSION 2.8)
 
 
+
 #LIBRARY
 include_directories(. lwext4)
 aux_source_directory(lwext4 LWEXT4_SRC)
@@ -20,6 +21,8 @@
     #Library size print
     add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
 else()
+    #Warning setup
+    set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic -std=gnu99")
     #Library size print
     add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)
     #Generic example target
--- a/ext4.h
+++ b/ext4.h
@@ -137,11 +137,8 @@
 typedef struct {
     uint32_t inode;
     uint16_t entry_length;
-    uint8_t  name_length;
-    union {
-        uint8_t name_length_high;
-        uint8_t inode_type;
-    };
+    uint8_t name_length;
+    uint8_t inode_type;
     uint8_t name[255];
 }ext4_direntry;
 
--- a/fs_test/lwext4_client.c
+++ b/fs_test/lwext4_client.c
@@ -101,6 +101,7 @@
         exit(-1);
     }
 
+    winsock_fini();
     return fd;
 }
 
--- a/fs_test/lwext4_server.c
+++ b/fs_test/lwext4_server.c
@@ -453,7 +453,7 @@
     rc = ext4_mount_point_stats(mount_point, &stats);
 
     if(rc != EOK)
-        return;
+        return rc;
 
     if(verbose){
         printf("\tinodes_count = %d\n", stats.inodes_count);
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -52,11 +52,11 @@
 
 /**@brief   Mount point OS dependent lock*/
 #define EXT4_MP_LOCK(_m)    \
-        do { (_m)->os_locks ? (_m)->os_locks->lock() : 0; }while(0)
+        do { if((_m)->os_locks)  (_m)->os_locks->lock(); }while(0)
 
 /**@brief   Mount point OS dependent unlock*/
 #define EXT4_MP_UNLOCK(_m)  \
-        do { (_m)->os_locks ? (_m)->os_locks->unlock() : 0; }while(0)
+        do { if((_m)->os_locks)  (_m)->os_locks->unlock(); }while(0)
 
 /**@brief   Mount point descrpitor.*/
 struct ext4_mountpoint {
--- a/lwext4/ext4_debug.h
+++ b/lwext4/ext4_debug.h
@@ -92,7 +92,7 @@
 #if CONFIG_DEBUG_PRINTF
 /**@brief   Debug printf.*/
 #define ext4_dprintf(m, ...)    do {                            \
-        (m & ext4_dmask_get()) ? printf(__VA_ARGS__) : (void)0; \
+        if(m & ext4_dmask_get())  printf(__VA_ARGS__); 			\
         fflush(stdout);                                         \
 }while(0)
 #else
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -78,7 +78,7 @@
 
     if ((ext4_get32(sb, rev_level) == 0) &&
             (ext4_get32(sb, minor_rev_level) < 5))
-        v |= ((uint16_t)de->name_length_high) << 8;
+        v |= ((uint16_t)de->in.name_length_high) << 8;
 
     return v;
 }
@@ -89,7 +89,7 @@
 
     if ((ext4_get32(sb, rev_level) == 0) &&
             (ext4_get32(sb, minor_rev_level) < 5))
-        de->name_length_high = len >> 8;
+        de->in.name_length_high = len >> 8;
 }
 
 
@@ -99,7 +99,7 @@
 {
     if ((ext4_get32(sb, rev_level) > 0) ||
             (ext4_get32(sb, minor_rev_level) >= 5))
-        return de->inode_type;
+        return de->in.inode_type;
 
     return EXT4_DIRECTORY_FILETYPE_UNKNOWN;
 }
@@ -110,7 +110,7 @@
 {
     if ((ext4_get32(sb, rev_level) > 0) ||
             (ext4_get32(sb, minor_rev_level) >= 5))
-        de->inode_type = type;
+        de->in.inode_type = type;
 }
 
 /****************************************************************************/
@@ -561,7 +561,7 @@
                 /* Cut tail of current entry */
                 ext4_dir_entry_ll_set_entry_length(dentry, used_space);
                 struct ext4_directory_entry_ll *new_entry =
-                        (void *) dentry + used_space;
+                        (void *) ((uint8_t *)dentry + used_space);
                 ext4_dir_write_entry(sb, new_entry,
                     free_space, child, name, name_len);
 
@@ -571,7 +571,7 @@
         }
 
         /* Jump to the next entry */
-        dentry = (void *) dentry + rec_len;
+        dentry = (void *) ((uint8_t *)dentry + rec_len);
     }
 
     /* No free space found for new entry */
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -595,7 +595,7 @@
     uint32_t count = ext4_dir_dx_countlimit_get_count(countlimit);
 
     struct ext4_directory_dx_entry *start_index = index_block->entries;
-    size_t bytes = (void *) (start_index + count) - (void *) (new_index_entry);
+    size_t bytes = (uint8_t *) (start_index + count) - (uint8_t *) (new_index_entry);
 
     memmove(new_index_entry + 1, new_index_entry, bytes);
 
@@ -625,7 +625,7 @@
     uint32_t block_size =
             ext4_sb_get_block_size(&inode_ref->fs->sb);
 
-    void *entry_buffer = malloc(block_size);
+    uint8_t *entry_buffer = malloc(block_size);
     if (entry_buffer == NULL)
         return ENOMEM;
 
@@ -651,7 +651,7 @@
 
     /* Load all valid entries to the buffer */
     struct ext4_directory_entry_ll *dentry = (void *)old_data_block->data;
-    void *entry_buffer_ptr = entry_buffer;
+    uint8_t *entry_buffer_ptr = entry_buffer;
     while ((void *)dentry < (void *)(old_data_block->data + block_size)) {
         /* Read only valid entries */
         if (ext4_dir_entry_ll_get_inode(dentry) && dentry->name_length) {
@@ -681,8 +681,8 @@
             idx++;
         }
 
-        dentry = (void *) dentry +
-                ext4_dir_entry_ll_get_entry_length(dentry);
+        dentry = (void *)((uint8_t *)dentry +
+                ext4_dir_entry_ll_get_entry_length(dentry));
     }
 
     /* Sort all entries */
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -513,8 +513,8 @@
     /* Compute the checksum only if the filesystem supports it */
     if (ext4_sb_check_read_only(sb,
             EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
-        void *base = bg;
-        void *checksum = &bg->checksum;
+        uint8_t  *base = (uint8_t  *)bg;
+        uint8_t  *checksum = (uint8_t  *)&bg->checksum;
 
         uint32_t offset = (uint32_t) (checksum - base);
 
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -403,6 +403,11 @@
 #define EXT4_DIRECTORY_FILETYPE_SOCK      6
 #define EXT4_DIRECTORY_FILETYPE_SYMLINK   7
 
+union ext4_directory_entry_ll_internal{
+    uint8_t name_length_high;  /* Higher 8 bits of name length */
+    uint8_t inode_type;        /* Type of referenced inode (in rev >= 0.5) */
+} __attribute__ ((packed));
+
 /**
  * Linked list directory entry structure
  */
@@ -411,10 +416,7 @@
     uint16_t entry_length;  /* Distance to the next directory entry */
     uint8_t name_length;    /* Lower 8 bits of name length */
 
-    union {
-        uint8_t name_length_high;  /* Higher 8 bits of name length */
-        uint8_t inode_type;        /* Type of referenced inode (in rev >= 0.5) */
-    } __attribute__ ((packed));
+    union ext4_directory_entry_ll_internal in;
 
     uint8_t name[EXT4_DIRECTORY_FILENAME_LEN];  /* Entry name */
 } __attribute__((packed)) ;
@@ -462,7 +464,7 @@
 struct ext4_directory_dx_root {
     struct ext4_directory_dx_dot_entry dots[2];
     struct ext4_directory_dx_root_info info;
-    struct ext4_directory_dx_entry entries[0];
+    struct ext4_directory_dx_entry entries[];
 };
 
 struct ext4_fake_directory_entry {
@@ -474,7 +476,7 @@
 
 struct ext4_directory_dx_node {
     struct ext4_fake_directory_entry fake;
-    struct ext4_directory_dx_entry entries[0];
+    struct ext4_directory_dx_entry entries[];
 };
 
 struct ext4_directory_dx_block {
@@ -536,10 +538,10 @@
 #define EXT4_EXTENT_MAGIC  0xF30A
 
 #define EXT4_EXTENT_FIRST(header) \
-        ((struct ext4_extent *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
+        ((struct ext4_extent *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
 
 #define EXT4_EXTENT_FIRST_INDEX(header) \
-        ((struct ext4_extent_index *) (((void *) (header)) + sizeof(struct ext4_extent_header)))
+        ((struct ext4_extent_index *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
 
 
 /* EXT3 HTree directory indexing */
@@ -550,7 +552,7 @@
 #define EXT2_HTREE_HALF_MD4_UNSIGNED        4
 #define EXT2_HTREE_TEA_UNSIGNED             5
 
-#define EXT2_HTREE_EOF                      0x7FFFFFFF
+#define EXT2_HTREE_EOF                      0x7FFFFFFFUL
 
 
 struct ext4_hash_info {