[Commits] 44f3058: Prevent undefined behavior if the table is already initialized

Vicențiu Ciorbaru vicentiu at mariadb.org
Tue Sep 20 23:42:34 EEST 2016


Hi Sergey, Monty!

CCed Monty as he last touched this code as part of MDEV-8408.

This patch comes after I found a warning during compilation that says that
we might be using the error variable as uninitialised.
Looking at the code:
  int error;
  /* ..... */
  if (!table->file->inited &&
      (error= table->file->ha_index_init(idx, 1)))
  /* ... */
  DBUG_RETURN(error != 0);

Here, if table->file->inited is actually set to true, the error variable is
never set. The problem is that i'm not sure if we should be returning a
failure or not. I considered that
having the table initialised _before_ this call would lead to
"not-an-error". Then again, the semantics are strange and I couldn't figure
out exactly which is the correct return value.

Thoughts?

Vicentiu

On Tue, 20 Sep 2016 at 14:17 Vicentiu Ciorbaru <vicentiu at mariadb.org> wrote:

> revision-id: 44f3058f54fa237ce9df7da2b18283a47b5b655e
> (mariadb-10.0.27-11-g44f3058)
> parent(s): 83d5b963bd38e327a673c5d4f4d70c8223f45dd2
> author: Vicențiu Ciorbaru
> committer: Vicențiu Ciorbaru
> timestamp: 2016-09-20 14:16:18 +0200
> message:
>
> Prevent undefined behavior if the table is already initialized
>
> The error variable ends up not initialized if the first statement in the
> if clause is false. This leads to us returning a result based on an
> unitialized value.
>
> ---
>  sql/records.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sql/records.cc b/sql/records.cc
> index a37f7a1..940fd97 100644
> --- a/sql/records.cc
> +++ b/sql/records.cc
> @@ -69,7 +69,7 @@ static int rr_index_desc(READ_RECORD *info);
>  bool init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
>                            bool print_error, uint idx, bool reverse)
>  {
> -  int error;
> +  int error= 0;
>    DBUG_ENTER("init_read_record_idx");
>
>    empty_record(table);
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.askmonty.org/pipermail/commits/attachments/20160920/9227db84/attachment.html>


More information about the commits mailing list