slcanpty: silence warning for signed index for the buf array
slcanpty.c: In function ‘pty2can’:
slcanpty.c:105:21: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
105 | buf[nbytes] = 0;
| ~~~~~~~~~~~~^~~
slcanpty.c:58:21: note: at offset [-2147483647, -1] into destination object ‘buf’ of size 200
58 | static char buf[200];
| ^~~
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/498/head
parent
a9260eab76
commit
2643d28a57
15
slcanpty.c
15
slcanpty.c
|
|
@ -53,24 +53,25 @@
|
||||||
int pty2can(int pty, int socket, struct can_filter *fi,
|
int pty2can(int pty, int socket, struct can_filter *fi,
|
||||||
int *is_open, int *tstamp)
|
int *is_open, int *tstamp)
|
||||||
{
|
{
|
||||||
int nbytes;
|
unsigned int nbytes;
|
||||||
char cmd;
|
char cmd;
|
||||||
static char buf[200];
|
static char buf[200];
|
||||||
char replybuf[10]; /* for answers to received commands */
|
char replybuf[10]; /* for answers to received commands */
|
||||||
int ptr;
|
int ptr;
|
||||||
struct can_frame frame;
|
struct can_frame frame;
|
||||||
int tmp, i;
|
int ret, tmp, i;
|
||||||
static int rxoffset = 0; /* points to the end of an received incomplete SLCAN message */
|
static unsigned int rxoffset = 0; /* points to the end of an received incomplete SLCAN message */
|
||||||
|
|
||||||
nbytes = read(pty, &buf[rxoffset], sizeof(buf)-rxoffset-1);
|
ret = read(pty, &buf[rxoffset], sizeof(buf)-rxoffset-1);
|
||||||
if (nbytes <= 0) {
|
if (ret <= 0) {
|
||||||
/* nbytes == 0 : no error but pty descriptor has been closed */
|
/* ret == 0 : no error but pty descriptor has been closed */
|
||||||
if (nbytes < 0)
|
if (ret < 0)
|
||||||
perror("read pty");
|
perror("read pty");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nbytes = ret;
|
||||||
/* reset incomplete message offset */
|
/* reset incomplete message offset */
|
||||||
nbytes += rxoffset;
|
nbytes += rxoffset;
|
||||||
rxoffset = 0;
|
rxoffset = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue