mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Removed toolchain specific warnings
- Comparisons with differently signed integer types - Incorrectly signed constant - Unreachable default returns - Leaked uninitialized variables in relocate goto statements
This commit is contained in:
		
							
								
								
									
										36
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -373,8 +373,8 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_dir_t *dir) { | ||||
|     // set defaults | ||||
|     dir->d.rev += 1; | ||||
|     dir->d.size = sizeof(dir->d)+4; | ||||
|     dir->d.tail[0] = -1; | ||||
|     dir->d.tail[1] = -1; | ||||
|     dir->d.tail[0] = 0xffffffff; | ||||
|     dir->d.tail[1] = 0xffffffff; | ||||
|     dir->off = sizeof(dir->d); | ||||
|  | ||||
|     // don't write out yet, let caller take care of that | ||||
| @@ -455,6 +455,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, | ||||
|     bool relocated = false; | ||||
|  | ||||
|     while (true) { | ||||
|         if (true) { | ||||
|             int err = lfs_bd_erase(lfs, dir->pair[0]); | ||||
|             if (err) { | ||||
|                 if (err == LFS_ERR_CORRUPT) { | ||||
| @@ -530,7 +531,8 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, | ||||
|  | ||||
|             // successful commit, check checksum to make sure | ||||
|             crc = 0xffffffff; | ||||
|         err = lfs_bd_crc(lfs, dir->pair[0], 0, 0x7fffffff & dir->d.size, &crc); | ||||
|             err = lfs_bd_crc(lfs, dir->pair[0], 0, | ||||
|                     0x7fffffff & dir->d.size, &crc); | ||||
|             if (err) { | ||||
|                 return err; | ||||
|             } | ||||
| @@ -538,6 +540,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, | ||||
|             if (crc == 0) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| relocate: | ||||
|         //commit was corrupted | ||||
| @@ -554,7 +557,7 @@ relocate: | ||||
|         } | ||||
|  | ||||
|         // relocate half of pair | ||||
|         err = lfs_alloc(lfs, &dir->pair[0]); | ||||
|         int err = lfs_alloc(lfs, &dir->pair[0]); | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
| @@ -791,8 +794,6 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir, | ||||
|             return err; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -1021,7 +1022,7 @@ static int lfs_ctz_find(lfs_t *lfs, | ||||
|         lfs_block_t head, lfs_size_t size, | ||||
|         lfs_size_t pos, lfs_block_t *block, lfs_off_t *off) { | ||||
|     if (size == 0) { | ||||
|         *block = -1; | ||||
|         *block = 0xffffffff; | ||||
|         *off = 0; | ||||
|         return 0; | ||||
|     } | ||||
| @@ -1053,6 +1054,7 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|         lfs_block_t head, lfs_size_t size, | ||||
|         lfs_off_t *block, lfs_block_t *off) { | ||||
|     while (true) { | ||||
|         if (true) { | ||||
|             // go ahead and grab a block | ||||
|             int err = lfs_alloc(lfs, block); | ||||
|             if (err) { | ||||
| @@ -1081,12 +1083,14 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|             if (size != lfs->cfg->block_size) { | ||||
|                 for (lfs_off_t i = 0; i < size; i++) { | ||||
|                     uint8_t data; | ||||
|                 int err = lfs_cache_read(lfs, rcache, NULL, head, i, &data, 1); | ||||
|                     int err = lfs_cache_read(lfs, rcache, NULL, | ||||
|                             head, i, &data, 1); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
|                     } | ||||
|  | ||||
|                 err = lfs_cache_prog(lfs, pcache, rcache, *block, i, &data, 1); | ||||
|                     err = lfs_cache_prog(lfs, pcache, rcache, | ||||
|                             *block, i, &data, 1); | ||||
|                     if (err) { | ||||
|                         if (err == LFS_ERR_CORRUPT) { | ||||
|                             goto relocate; | ||||
| @@ -1114,7 +1118,8 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|                 } | ||||
|  | ||||
|                 if (i != skips-1) { | ||||
|                 err = lfs_cache_read(lfs, rcache, NULL, head, 4*i, &head, 4); | ||||
|                     err = lfs_cache_read(lfs, rcache, NULL, | ||||
|                             head, 4*i, &head, 4); | ||||
|                     if (err) { | ||||
|                         return err; | ||||
|                     } | ||||
| @@ -1125,6 +1130,7 @@ static int lfs_ctz_extend(lfs_t *lfs, | ||||
|  | ||||
|             *off = 4*skips; | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
| relocate: | ||||
|         LFS_DEBUG("Bad block at %d", *block); | ||||
| @@ -1161,8 +1167,6 @@ static int lfs_ctz_traverse(lfs_t *lfs, | ||||
|  | ||||
|         index -= 1; | ||||
|     } | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -1200,7 +1204,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, | ||||
|         entry.d.elen = sizeof(entry.d) - 4; | ||||
|         entry.d.alen = 0; | ||||
|         entry.d.nlen = strlen(path); | ||||
|         entry.d.u.file.head = -1; | ||||
|         entry.d.u.file.head = 0xffffffff; | ||||
|         entry.d.u.file.size = 0; | ||||
|         err = lfs_dir_append(lfs, &cwd, &entry, path); | ||||
|         if (err) { | ||||
| @@ -1222,7 +1226,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, | ||||
|     file->pos = 0; | ||||
|  | ||||
|     if (flags & LFS_O_TRUNC) { | ||||
|         file->head = -1; | ||||
|         file->head = 0xffffffff; | ||||
|         file->size = 0; | ||||
|     } | ||||
|  | ||||
| @@ -1589,13 +1593,13 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, | ||||
|     if (whence == LFS_SEEK_SET) { | ||||
|         file->pos = off; | ||||
|     } else if (whence == LFS_SEEK_CUR) { | ||||
|         if (-off > file->pos) { | ||||
|         if ((lfs_off_t)-off > file->pos) { | ||||
|             return LFS_ERR_INVAL; | ||||
|         } | ||||
|  | ||||
|         file->pos = file->pos + off; | ||||
|     } else if (whence == LFS_SEEK_END) { | ||||
|         if (-off > file->size) { | ||||
|         if ((lfs_off_t)-off > file->size) { | ||||
|             return LFS_ERR_INVAL; | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user