From 3e134aef3e6fd7a53fe67c1d431eda15fd8e8cdf Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 14 Dec 2023 21:23:34 -0500 Subject: [PATCH] Adjust DEBUG_TRANS enabled code to work with current kernels and compilers The last element in _stp_command_names is in _stp_command_name[STP_MAX_CMD]. Thus, the array has STP_MAX_CMD+1 elements rather than STP_MAX_CMD elements. The compiler would flag the access beyond the end of the array due to the incorrectly sized array. The min operation provided by the kernel's minmax.h include does type checking. Needed to type cast STP_MAX_CMD to match the other argument and avoid the compiler flagging the type mismatch as an error. --- runtime/transport/control.c | 4 ++-- runtime/transport/transport_msgs.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/transport/control.c b/runtime/transport/control.c index d0a8bdf53..35608731c 100644 --- a/runtime/transport/control.c +++ b/runtime/transport/control.c @@ -57,7 +57,7 @@ static ssize_t _stp_ctl_write_cmd(struct file *file, const char __user *buf, siz #if defined(DEBUG_TRANS) && (DEBUG_TRANS >= 2) if (type < STP_MAX_CMD) - dbug_trans2("Got %s. euid=%ld, len=%d\n", _stp_command_name[min(type,STP_MAX_CMD)] ?: "?", + dbug_trans2("Got %s. euid=%ld, len=%d\n", _stp_command_name[min(type, (u32)STP_MAX_CMD)] ?: "?", (long)euid, (int)count); #endif @@ -212,7 +212,7 @@ out: #if defined(DEBUG_TRANS) && (DEBUG_TRANS >= 2) if (type < STP_MAX_CMD) dbug_trans2("Completed %s (rc=%d)\n", - _stp_command_name[min(type,STP_MAX_CMD)] ?: "?", + _stp_command_name[min(type, (u32)STP_MAX_CMD)] ?: "?", rc); #endif return rc; diff --git a/runtime/transport/transport_msgs.h b/runtime/transport/transport_msgs.h index e3aa995b1..be1f3a8b8 100644 --- a/runtime/transport/transport_msgs.h +++ b/runtime/transport/transport_msgs.h @@ -102,7 +102,7 @@ enum }; #ifdef DEBUG_TRANS -static const char *_stp_command_name[STP_MAX_CMD] = { +static const char *_stp_command_name[STP_MAX_CMD+1] = { [STP_START]="STP_START", "STP_EXIT", "STP_OOB_DATA", -- 2.43.5