poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Out of bounds check on pk_array* interface.


From: Jose E. Marchesi
Subject: Re: [PATCH] Out of bounds check on pk_array* interface.
Date: Thu, 02 Jul 2020 20:29:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Kostas.

    Hello, I have modified pk_array* interface on libpoke to check for out of
    bounds indexing.

    diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
    index 1722a4e6..12304332 100644
    --- a/libpoke/pk-val.c
    +++ b/libpoke/pk-val.c
    @@ -269,23 +269,39 @@ pk_array_nelem (pk_val array)
     pk_val
     pk_array_elem_val (pk_val array, uint64_t idx)
     {
    +  if (idx >= pk_uint_value( pk_array_nelem (array))) {

Please follow GNU coding standards:
- In function calls, put a space between the name of the function and
  the list of arguments.
- Do not use a whitespace between ( and pk_array_nelem.
- Put the beginning curly brace of a statement in its own line.

Example:

if (idx >= pk_uint_value (pk_array_nelem (array)))
  {
    bleh;
    blah;
  }

     void
     pk_array_set_elem_val (pk_val array, uint64_t idx, pk_val val)
     {
    +  if (idx >= pk_uint_value( pk_array_nelem (array))) {
    +    return;
    +  }
    +
       PVM_VAL_ARR_ELEM_VALUE (array, idx) = val;
     }

If you reverse the logic in the conditional you save a return statement
and the code is much more clear IMO:

void
pk_array_set_elem_val (pk_val array, uint64_t idx, pk_val val)
{
  if (idx < pk_uint_value (pk_array_nelem (array)))
    PVM_VAL_ARR_ELEM_VALUE (array, idx) = val;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]