diff --git a/include/openthread/diag.h b/include/openthread/diag.h index 869400a23..96571f9c0 100644 --- a/include/openthread/diag.h +++ b/include/openthread/diag.h @@ -54,6 +54,9 @@ extern "C" { /** * This function processes a factory diagnostics command line. * + * The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the + * output buffer. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aArgsLength The number of elements in @p aArgs. * @param[in] aArgs An array of arguments. @@ -74,6 +77,9 @@ otError otDiagProcessCmd(otInstance *aInstance, /** * This function processes a factory diagnostics command line. * + * The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the + * output buffer. + * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aString A NULL-terminated input string. * @param[out] aOutput The diagnostics execution result. diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 5b6a2cae6..3f8b812e5 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (137) +#define OPENTHREAD_API_VERSION (138) /** * @addtogroup api-instance diff --git a/include/openthread/platform/diag.h b/include/openthread/platform/diag.h index d8dcc9d77..9dee346c2 100644 --- a/include/openthread/platform/diag.h +++ b/include/openthread/platform/diag.h @@ -59,6 +59,9 @@ extern "C" { /** * This function processes a factory diagnostics command line. * + * The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the + * output buffer. + * * @param[in] aInstance The OpenThread instance for current request. * @param[in] aArgsLength The number of arguments in @p aArgs. * @param[in] aArgs The arguments of diagnostics command line. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 002def7af..dd0b79efb 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -4521,12 +4521,9 @@ otError Interpreter::ProcessDiag(Arg aArgs[]) char output[OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE]; // all diagnostics related features are processed within diagnostics module - output[0] = '\0'; - output[sizeof(output) - 1] = '\0'; - Arg::CopyArgsToStringArray(aArgs, args); - error = otDiagProcessCmd(mInstance, Arg::GetArgsLength(aArgs), args, output, sizeof(output) - 1); + error = otDiagProcessCmd(mInstance, Arg::GetArgsLength(aArgs), args, output, sizeof(output)); OutputFormat("%s", output); diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 2586973a8..0b439c05b 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1340,8 +1340,6 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader) VerifyOrExit(error == OT_ERROR_NONE, error = WriteLastStatusFrame(aHeader, ThreadErrorToSpinelStatus(error))); - output[sizeof(output) - 1] = '\0'; - #if OPENTHREAD_MTD || OPENTHREAD_FTD // TODO do not pass mfg prefix // skip mfg prefix from wpantund @@ -1351,7 +1349,7 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader) } #endif - otDiagProcessCmdLine(mInstance, string, output, sizeof(output) - 1); + otDiagProcessCmdLine(mInstance, string, output, sizeof(output)); // Prepare the response SuccessOrExit(error = mEncoder.BeginFrame(aHeader, SPINEL_CMD_PROP_VALUE_IS, SPINEL_PROP_NEST_STREAM_MFG));