From 00fa0aa3e59d49d72c961f893e524fc20563aa67 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Mon, 6 Jan 2014 18:21:49 -0500 Subject: Make sure not to use a negative payload length. --- src/obd2/obd2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit 1.2.3-korg