# HG changeset patch # User John W. Eaton # Date 1637777718 18000 # Node ID 5c6c5c8bbefd279c5a4ebf3100790550f19396f0 # Parent 29efaa1d32d7138a2159bb8b78e4c22df86ea8f3 mxAddField: Allow keys to contain any characters (bug #61537) * mex.cc (mxArray_struct::add_field): Don't validate key. (valid_key): Delete unused static function. diff -r 29efaa1d32d7 -r 5c6c5c8bbefd libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Wed Nov 24 19:09:14 2021 +0100 +++ b/libinterp/corefcn/mex.cc Wed Nov 24 13:15:18 2021 -0500 @@ -277,30 +277,6 @@ return max_len; } -static int -valid_key (const char *key) -{ - int retval = 0; - - int nel = strlen (key); - - if (nel > 0) - { - if (isalpha (key[0])) - { - for (int i = 1; i < nel; i++) - { - if (! (isalnum (key[i]) || key[i] == '_')) - return retval; - } - - retval = 1; - } - } - - return retval; -} - // ------------------------------------------------------------------ mxArray_base::mxArray_base (bool interleaved) @@ -2767,48 +2743,45 @@ { int retval = -1; - if (valid_key (key)) + m_nfields++; + + m_fields = static_cast + (mxRealloc (m_fields, m_nfields * sizeof (char *))); + + if (m_fields) { - m_nfields++; - - m_fields = static_cast - (mxRealloc (m_fields, m_nfields * sizeof (char *))); - - if (m_fields) + m_fields[m_nfields-1] = mxArray::strsave (key); + + mwSize nel = get_number_of_elements (); + + mwSize ntot = m_nfields * nel; + + mxArray **new_data; + new_data = static_cast + (mxArray::malloc (ntot * sizeof (mxArray *))); + + if (new_data) { - m_fields[m_nfields-1] = mxArray::strsave (key); - - mwSize nel = get_number_of_elements (); - - mwSize ntot = m_nfields * nel; - - mxArray **new_data; - new_data = static_cast - (mxArray::malloc (ntot * sizeof (mxArray *))); - - if (new_data) + mwIndex j = 0; + mwIndex k = 0; + mwIndex n = 0; + + for (mwIndex i = 0; i < ntot; i++) { - mwIndex j = 0; - mwIndex k = 0; - mwIndex n = 0; - - for (mwIndex i = 0; i < ntot; i++) + if (++n == m_nfields) { - if (++n == m_nfields) - { - new_data[j++] = nullptr; - n = 0; - } - else - new_data[j++] = m_data[k++]; + new_data[j++] = nullptr; + n = 0; } - - mxFree (m_data); - - m_data = new_data; - - retval = m_nfields - 1; + else + new_data[j++] = m_data[k++]; } + + mxFree (m_data); + + m_data = new_data; + + retval = m_nfields - 1; } }