-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: rpc: openthread: dynamic allocation for CLI commands #19320
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 93d84930d87841bdcb4d3f8148d23181a7fc47ad more detailssdk-nrf:
Github labels
List of changed files detected by CI (3)
Outputs:ToolchainVersion: b77d8c1312 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
e76b1ef
to
e540759
Compare
You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds. Note: This comment is automatically posted by the Documentation Publish GitHub Action. |
e540759
to
e9c4460
Compare
@@ -232,7 +232,7 @@ char *nrf_rpc_decode_str(struct nrf_rpc_cbor_ctx *ctx, char *buffer, size_t buff | |||
/** @brief Decode a string pointer and length. Moves CBOR pointer past string on success. | |||
* | |||
* @param[in,out] ctx CBOR decoding context. | |||
* @param[out] size String length. | |||
* @param[out] len String length. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be corrected in the first commit that introduces nrf_rpc_decode_str_ptr_and_len()
, not here where dynamic allocation is added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (ptr) { | ||
buffer = malloc(len + 1); | ||
if (buffer) { | ||
memcpy(buffer, ptr, len); | ||
buffer[len] = '\0'; | ||
} | ||
} | ||
|
||
if (!nrf_rpc_decoding_done_and_check(group, ctx)) { | ||
ot_rpc_report_cmd_decoding_error(OT_RPC_CMD_CLI_INPUT_LINE); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function can return here without freeing buffer
. Is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed
e9c4460
to
59693b0
Compare
memcpy(buffer, ptr, len); | ||
buffer[len] = '\0'; | ||
} | ||
} | ||
|
||
if (!nrf_rpc_decoding_done_and_check(group, ctx)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move this before the allocation and copying which turn out to be unnecessary when this fails? This extra call to free
would not be needed then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nrf_rpc_decoding_done_and_check()
frees the buffer which holds the data to be stored in the buffer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked nrf_rpc commit
This commit adds new helper function nrf_rpc_decode_str_ptr_and_len() that decodes CBOR string without copying it to a buffer. It allows to get string length before buffer allocation. Signed-off-by: Konrad Derda <[email protected]>
CLI commands may require large buffer for command strings. This commit introduces usage of dynamic allocation to avoid usage of huge static buffer. Signed-off-by: Konrad Derda <[email protected]>
59693b0
to
93d8493
Compare
No description provided.