Fixed NULL pointer use in tmpfs.

This commit is contained in:
Fotis Panagiotopoulos
2022-10-13 16:59:44 +03:00
committed by Xiang Xiao
parent 403c657f42
commit a0918d6d5e
+18 -4
View File
@@ -1496,8 +1496,15 @@ static ssize_t tmpfs_read(FAR struct file *filep, FAR char *buffer,
/* Copy data from the memory object to the user buffer */ /* Copy data from the memory object to the user buffer */
memcpy(buffer, &tfo->tfo_data[startpos], nread); if (tfo->tfo_data != NULL)
filep->f_pos += nread; {
memcpy(buffer, &tfo->tfo_data[startpos], nread);
filep->f_pos += nread;
}
else
{
DEBUGASSERT(tfo->tfo_size == 0 && nread == 0);
}
/* Release the lock on the file */ /* Release the lock on the file */
@@ -1553,8 +1560,15 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer,
/* Copy data from the memory object to the user buffer */ /* Copy data from the memory object to the user buffer */
memcpy(&tfo->tfo_data[startpos], buffer, nwritten); if (tfo->tfo_data != NULL)
filep->f_pos += nwritten; {
memcpy(&tfo->tfo_data[startpos], buffer, nwritten);
filep->f_pos += nwritten;
}
else
{
DEBUGASSERT(tfo->tfo_size == 0 && nwritten == 0);
}
/* Release the lock on the file */ /* Release the lock on the file */