[PATCH 3/3] Cochran: Clarified that a low-speed read of 0 bytes means 32k bytes

John Van Ostrand john at vanostrand.com
Fri Aug 11 07:33:24 PDT 2017


Reading using the low-speed read command returns 32K bytes when
asked for 0. This is handy to use, but we should handle a request
for 0 by returning without a read.
---
 src/cochran_commander.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index 068fd04..9670aea 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -500,6 +500,16 @@ cochran_commander_read (cochran_commander_device_t *device, dc_event_progress_t
 	case 24:
 		// Commander uses 24 byte addressing
 		if (device->layout->baudrate == 9600) {
+			// This read command will return 32K bytes if asked to
+			// read 0 bytes. So we can allow a size of up to
+			// 0x10000 but if the user asks for 0 bytes we
+			// should just return success otherwise we'll end
+			// end up running past the buffer.
+			if (size > 0x10000)
+				return DC_STATUS_INVALIDARGS;
+			if (size == 0)
+				return DC_STATUS_SUCCESS;
+
 			// Older commander, use low-speed read command
 			command[0] = 0x05;
 			command[1] = (address      ) & 0xff;
-- 
2.4.11



More information about the devel mailing list