MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rw_verify_area

Function rw_verify_area

components/dfs/dfs_v2/src/dfs_file.c:238–253  ·  view source on GitHub ↗

* @brief Verify read/write area parameters and limit count size * * This function checks the validity of read/write parameters and limits the count * to a maximum value (MAX_RW_COUNT) to prevent overflow. It ensures the position * and count values are within valid ranges. * * @param[in] file Pointer to the file structure (unused in current implementation) * @param[in] ppos Pointer to the po

Source from the content-addressed store, hash-verified

236 * so that others won't have to do range checks all the time.
237 */
238ssize_t rw_verify_area(struct dfs_file *file, off_t *ppos, size_t count)
239{
240 off_t pos;
241 ssize_t retval = -EINVAL;
242
243 if ((size_t)count < 0)
244 return retval;
245 pos = *ppos;
246 if (pos < 0)
247 {
248 if (count >= -pos) /* both values are in 0..LLONG_MAX */
249 return -EOVERFLOW;
250 }
251
252 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
253}
254
255/**
256 * @brief Get the current file position

Callers 4

dfs_file_preadFunction · 0.85
dfs_file_readFunction · 0.85
dfs_file_pwriteFunction · 0.85
dfs_file_writeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected