diff options
| author | Tangyuxin <[email protected]> | 2022-09-20 22:31:11 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-20 10:31:11 -0400 |
| commit | a4829b1c004015cca489679cc335b6089aa9da31 (patch) | |
| tree | 3e346e76bb1c77b5b189ca28b053daeaea5154e9 /components/dfs | |
| parent | 746d7a01bdb29c692b696780f938f11253ae1103 (diff) | |
[fix] Fix simulator compilation warnings (#6438)
* [fix] Fix simulator compilation warnings
* Update bsp/simulator/rtconfig_project.h
Co-authored-by: Man, Jianting (Meco) <[email protected]>
Diffstat (limited to 'components/dfs')
| -rw-r--r-- | components/dfs/filesystems/romfs/dfs_romfs.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 1a467be242..981e5f2ee8 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -157,7 +157,7 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count) int dfs_romfs_lseek(struct dfs_fd *file, off_t offset) { - if (offset <= file->size) + if (offset >= 0 && (rt_size_t)offset <= file->size) { file->pos = offset; return file->pos; @@ -243,6 +243,7 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) { rt_size_t index; + rt_size_t len; const char *name; struct dirent *d; struct romfs_dirent *dirent, *sub_dirent; @@ -261,7 +262,7 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) return -EINVAL; index = 0; - for (index = 0; index < count && file->pos < file->size; index ++) + for (index = 0; index < count && (rt_size_t)file->pos < file->size; index ++) { d = dirp + index; @@ -274,7 +275,9 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) else d->d_type = DT_REG; - d->d_namlen = rt_strlen(name); + len = rt_strlen(name); + RT_ASSERT(len <= RT_UINT8_MAX); + d->d_namlen = (rt_uint8_t)len; d->d_reclen = (rt_uint16_t)sizeof(struct dirent); rt_strncpy(d->d_name, name, DFS_PATH_MAX); |
