Cynerd commented on code in PR #17441:
URL: https://github.com/apache/nuttx/pull/17441#discussion_r2609479328
##########
drivers/can/can.c:
##########
@@ -518,7 +518,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char
*buffer,
/* ret can be more than buflen due to roundup, so return at most buflen */
- return ret ? MIN(ret, buflen) : -EMSGSIZE;
+ return ret ? MIN(ret, (int)buflen) : -EMSGSIZE;
Review Comment:
```suggestion
return ret ? MIN(ret, (ssize_t)buflen) : -EMSGSIZE;
```
##########
drivers/can/can.c:
##########
@@ -744,7 +744,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const
char *buffer,
* can be more due to roundup.
*/
- ret = MIN(nsent, buflen);
+ ret = MIN(nsent, (int)buflen);
Review Comment:
```suggestion
ret = MIN(nsent, (ssize_t)buflen);
```
`nsent` is of type `ssize_t` and `buflen` of `size_t`. The result should be
of type `ssize_t`. Thus, the type should have been `ssize_t`, not `int`.
##########
drivers/can/can.c:
##########
Review Comment:
```suggestion
ssize_t ret = 0;
```
I think that we should switch this variable to the returned type. We do
assign to this variable `int` through the code, but we then return it as
`ssize_t` anyway. There are no guarantees that `int` will fit `ssize_t` and
vice versa, but because it ends up being `ssize_t` anyway, I would use
`ssize_t` here instead. Most of the time it will have no difference, but it
seems more correct to do so to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]