aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 18:21:49 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-06 18:21:49 -0500
commit00fa0aa3e59d49d72c961f893e524fc20563aa67 (patch)
treeb1f43385cbd4e260dcce49504da1a9af5ca6ac03 /src
parent50c63116eba8ea3703b44d82f19eb408ad9d7007 (diff)
Make sure not to use a negative payload length.
Diffstat (limited to 'src')
-rw-r--r--src/obd2/obd2.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/obd2/obd2.c b/src/obd2/obd2.c
index cfede4e9..3dad886a 100644
--- a/src/obd2/obd2.c
+++ b/src/obd2/obd2.c
@@ -14,6 +14,10 @@
#define NEGATIVE_RESPONSE_MODE_INDEX 1
#define NEGATIVE_RESPONSE_NRC_INDEX 2
+#ifndef MAX
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#endif
+
DiagnosticShims diagnostic_init_shims(LogShim log,
SendCanMessageShim send_can_message,
SetTimerShim set_timer) {
@@ -146,7 +150,7 @@ static bool handle_positive_response(DiagnosticRequestHandle* handle,
}
uint8_t payload_index = 1 + handle->request.pid_length;
- response->payload_length = message->size - payload_index;
+ response->payload_length = MAX(0, message->size - payload_index);
if(response->payload_length > 0) {
memcpy(response->payload, &message->payload[payload_index],
response->payload_length);