Re: [PATCH] rv: Fix addition on an uninitialized variable 'run'

From: Daniel Bristot de Oliveira
Date: Mon Apr 24 2023 - 05:09:49 EST


On 4/17/23 12:39, Colin Ian King wrote:
> The variable run is not initialized


Oops, that is a problem, it should be initialized as 0.

however it is being accumulated
> by the return value from the call to ikm_run_monitor. Fix this by
> replacing the += with an assignment since this is the first point
> where run is being assigned.
>
> Fixes: 4bc4b131d44c ("rv: Add rv tool")
>
> Signed-off-by: Colin Ian King <colin.i.king@xxxxxxxxx>
> ---
> tools/verification/rv/src/rv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c
> index e601cd9c411e..da647ad4e733 100644
> --- a/tools/verification/rv/src/rv.c
> +++ b/tools/verification/rv/src/rv.c
> @@ -111,7 +111,7 @@ static void rv_mon(int argc, char **argv)
> * Call all possible monitor implementations, looking
> * for the [monitor].
> */
> - run += ikm_run_monitor(monitor_name, argc-1, &argv[1]);
> + run = ikm_run_monitor(monitor_name, argc-1, &argv[1]);

So, in the future, there will be more monitors types, and so we will check
other functions to see if they find the monitor by name. Thus, the += is correct,
what is not correct the run not being initialized.

Mind sending a patch initializing the run = 0?

Thanks!
-- Daniel


> if (!run)
> err_msg("rv: monitor %s does not exist\n", monitor_name);