octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #63466] Possible invalid memory access in NDAr


From: anonymous
Subject: [Octave-bug-tracker] [bug #63466] Possible invalid memory access in NDArray::dim3()
Date: Sun, 4 Dec 2022 08:14:31 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?63466>

                 Summary: Possible invalid memory access in NDArray::dim3()
                 Project: GNU Octave
               Submitter: None
               Submitted: Sun 04 Dec 2022 01:14:29 PM UTC
                Category: Libraries
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Unexpected Error or Warning
                  Status: None
             Assigned to: None
         Originator Name: Reinhard
        Originator Email: octave-user@a1.net
             Open/Closed: Open
                 Release: 7.3.0
         Discussion Lock: Any
        Operating System: GNU/Linux
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Sun 04 Dec 2022 01:14:29 PM UTC By: Anonymous
It seems that a call to NDArray::dim3() is not a safe operation in C++ code.
For example if you have code like this,

void func(NDArray& x)
{
  octave_idx_type n = x.dim3();
}

the value of n might be undefined if the dim_vector has less then three
dimensions. So, the correct code should be:

void func(NDArray& x)
{
  octave_idx_type n = x.ndims() >= 3 ? x.dim3() : 1;
}

But why do we have a function like NDArray::dim3(), if it is not safe to call
without checking ndims? For example, code like this would be more concise.

void func(NDArray& x)
{
  octave_idx_type n = x.ndims() > 2 ? x.dims()(2) : 1;
}

In contradiction to that, NDArray::dim1() and NDArray::dim2() are always valid
because dim_vector will allocate space for at least two dimensions. So, it
makes sense to have those functions defined.
I would suggest either to make NDArray::dim3() safe or to remove it.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63466>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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