|
From: openocd-gerrit <ope...@us...> - 2026-05-30 18:17:44
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via fe239d9ffe8745effcd58e825e7169dd902c5c22 (commit)
from 9013ad2e5ebbb2e64f3af1c75cc33164f93c4a08 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fe239d9ffe8745effcd58e825e7169dd902c5c22
Author: Antonio Borneo <bor...@gm...>
Date: Mon May 18 10:56:07 2026 +0200
target: profile: avoid division by zero
Issue detected by scan-build.
The function target_profiling() can return with num_of_samples==0
and this will trigger a division by zero.
Check the value of num_of_samples before continuing.
While there, simplify the return path and the return value.
Fixes: dcf628298534 ("target: filter and sort pc samples before storing")
Change-Id: I74faa7de5c7fac6f8c862e338d2de5492a0dd14a
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9659
Tested-by: jenkins
Reviewed-by: Richard Allen <rs...@gm...>
diff --git a/src/target/target.c b/src/target/target.c
index 4d8741238..d68e9afb1 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -4331,6 +4331,12 @@ COMMAND_HANDLER(handle_profile_command)
return retval;
}
+ if (!num_of_samples) {
+ command_print(CMD, "Wrote no samples");
+ free(samples);
+ return ERROR_OK;
+ }
+
if (with_range) {
uint32_t num_filtered_samples = 0;
for (uint32_t in = 0; in < num_of_samples; ++in) {
@@ -4342,19 +4348,21 @@ COMMAND_HANDLER(handle_profile_command)
if (duration_ms < 1)
duration_ms = 0;
num_of_samples = num_filtered_samples;
+
+ if (!num_of_samples) {
+ command_print(CMD, "Wrote no samples in the requested range");
+ free(samples);
+ return ERROR_OK;
+ }
}
- if (num_of_samples) {
- qsort(samples, num_of_samples, sizeof(samples[0]), compare_pc32);
+ qsort(samples, num_of_samples, sizeof(samples[0]), compare_pc32);
- write_gmon(samples, num_of_samples, CMD_ARGV[1], target, duration_ms);
- command_print(CMD, "Wrote %s", CMD_ARGV[1]);
- } else {
- command_print(CMD, "Wrote no samples");
- }
+ write_gmon(samples, num_of_samples, CMD_ARGV[1], target, duration_ms);
+ command_print(CMD, "Wrote %s", CMD_ARGV[1]);
free(samples);
- return retval;
+ return ERROR_OK;
}
COMMAND_HANDLER(handle_target_read_memory)
-----------------------------------------------------------------------
Summary of changes:
src/target/target.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|