X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/b34a548a5dfd2f0b068fd835a4cd51680d851068..fb2dd0f20bd6264291dccb5e97609a23cae2fd1a:/lincan/src/write.c diff --git a/lincan/src/write.c b/lincan/src/write.c index 1869c97..1760bc2 100644 --- a/lincan/src/write.c +++ b/lincan/src/write.c @@ -20,10 +20,10 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t * struct canque_edge_t *qedge; struct canque_slot_t *slot; int ret = 0; - int bytes_to_copy = 0; + unsigned bytes_to_copy; if(!canuser || (canuser->magic != CAN_USER_MAGIC)){ - CANMSG("can_close: bad canuser magic\n"); + CANMSG("can_write: bad canuser magic\n"); return -ENODEV; } @@ -32,7 +32,7 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t * DEBUGMSG("this will always return 0 !\n"); return 0; } - if (length > 8 * sizeof(struct canmsg_t)) { + if (length > INT_MAX) { CANMSG("Trying to write more than is supported.\n"); return -1; } @@ -85,7 +85,8 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t * /* * Try to send more messages */ - while (bytes_to_copy > 0) { + while (bytes_to_copy >= sizeof(struct canmsg_t)) { + bytes_to_copy -= sizeof(struct canmsg_t); /* Prepare first message */ copy_from_user(&msg_buff, buffer, sizeof(struct canmsg_t)); /* Automatic selection of extended format if "extended" set and ID>2047 */ @@ -96,7 +97,6 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t * slot->msg=msg_buff; canque_put_inslot(qends, qedge, slot); buffer += sizeof(struct canmsg_t); - bytes_to_copy -= sizeof(struct canmsg_t); } if(file->f_flags & O_SYNC) {