libftdi Archives

Subject: libftdi_write_data: argument #2 should be const

From: bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Cc: Joerg Wunsch <j@xxxxxxxxxxxxxxxxx>
Date: Tue, 3 Sep 2013 11:03:50 +0200
Hallo Jarosch,

Joerg Wunsch <j@xxxxxxxxxxxxxxxxx> noted that in libftdi_write_data() the
buffer that is sent is only accessed reeading and so should be const. Please
consider appended patch ( if I got "const unsigned char *" versus "unsigned
char const *" right).

Bye

PS: Much fun for your holidays!

-- 
Uwe Bonnes                bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 5518b5476b2b28a9013916a01a1debfb0272ca74 Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 3 Sep 2013 10:57:38 +0200
Subject: The buffer in ftdi_write_data() is only accessed reading and so
 should be const.

---
 src/ftdi.c | 4 ++--
 src/ftdi.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index c19810b..8124985 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1369,7 +1369,7 @@ int ftdi_set_line_property2(struct ftdi_context *ftdi, 
enum ftdi_bits_type bits,
     \retval <0: error code from usb_bulk_write()
     \retval >0: number of bytes written
 */
-int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
+int ftdi_write_data(struct ftdi_context *ftdi, const unsigned char *buf, int 
size)
 {
     int offset = 0;
     int actual_length;
@@ -1384,7 +1384,7 @@ int ftdi_write_data(struct ftdi_context *ftdi, unsigned 
char *buf, int size)
         if (offset+write_size > size)
             write_size = size-offset;
 
-        if (libusb_bulk_transfer(ftdi->usb_dev, ftdi->in_ep, buf+offset, 
write_size, &actual_length, ftdi->usb_write_timeout) < 0)
+        if (libusb_bulk_transfer(ftdi->usb_dev, ftdi->in_ep, (unsigned char 
*)buf+offset, write_size, &actual_length, ftdi->usb_write_timeout) < 0)
             ftdi_error_return(-1, "usb bulk write failed");
 
         offset += actual_length;
diff --git a/src/ftdi.h b/src/ftdi.h
index 3d97dd9..a0ad8b4 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -502,7 +502,7 @@ extern "C"
     int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int 
chunksize);
     int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
 
-    int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int 
size);
+    int ftdi_write_data(struct ftdi_context *ftdi, const unsigned char *buf, 
int size);
     int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int 
chunksize);
     int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int 
*chunksize);
 
-- 
1.8.1.4


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread