Skip to content

Commit 1711bde

Browse files
authored
Merge pull request #886 from BrianPugh/macro-sanity-check
Add value-range checks for user-definable macros at compile-time
2 parents 3513ff1 + 6691718 commit 1711bde

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lfs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,21 @@ static int lfs_rawremoveattr(lfs_t *lfs, const char *path, uint8_t type) {
41084108

41094109

41104110
/// Filesystem operations ///
4111+
4112+
// compile time checks, see lfs.h for why these limits exist
4113+
#if LFS_NAME_MAX > 1022
4114+
#error "Invalid LFS_NAME_MAX, must be <= 1022"
4115+
#endif
4116+
4117+
#if LFS_FILE_MAX > 2147483647
4118+
#error "Invalid LFS_FILE_MAX, must be <= 2147483647"
4119+
#endif
4120+
4121+
#if LFS_ATTR_MAX > 1022
4122+
#error "Invalid LFS_ATTR_MAX, must be <= 1022"
4123+
#endif
4124+
4125+
// common filesystem initialization
41114126
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
41124127
lfs->cfg = cfg;
41134128
lfs->block_count = cfg->block_count; // May be 0

lfs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ typedef uint32_t lfs_block_t;
5252
#endif
5353

5454
// Maximum size of a file in bytes, may be redefined to limit to support other
55-
// drivers. Limited on disk to <= 4294967296. However, above 2147483647 the
56-
// functions lfs_file_seek, lfs_file_size, and lfs_file_tell will return
57-
// incorrect values due to using signed integers. Stored in superblock and
58-
// must be respected by other littlefs drivers.
55+
// drivers. Limited on disk to <= 2147483647. Stored in superblock and must be
56+
// respected by other littlefs drivers.
5957
#ifndef LFS_FILE_MAX
6058
#define LFS_FILE_MAX 2147483647
6159
#endif

0 commit comments

Comments
 (0)