Skip to content

Commit

Permalink
Merge pull request #886 from BrianPugh/macro-sanity-check
Browse files Browse the repository at this point in the history
Add value-range checks for user-definable macros at compile-time
  • Loading branch information
geky authored Jan 19, 2024
2 parents 3513ff1 + 6691718 commit 1711bde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4108,6 +4108,21 @@ static int lfs_rawremoveattr(lfs_t *lfs, const char *path, uint8_t type) {


/// Filesystem operations ///

// compile time checks, see lfs.h for why these limits exist
#if LFS_NAME_MAX > 1022
#error "Invalid LFS_NAME_MAX, must be <= 1022"
#endif

#if LFS_FILE_MAX > 2147483647
#error "Invalid LFS_FILE_MAX, must be <= 2147483647"
#endif

#if LFS_ATTR_MAX > 1022
#error "Invalid LFS_ATTR_MAX, must be <= 1022"
#endif

// common filesystem initialization
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->cfg = cfg;
lfs->block_count = cfg->block_count; // May be 0
Expand Down
6 changes: 2 additions & 4 deletions lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ typedef uint32_t lfs_block_t;
#endif

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

0 comments on commit 1711bde

Please sign in to comment.