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

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

[Octave-bug-tracker] [bug #54373] strncmp does not compute result accura


From: Rik
Subject: [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length
Date: Wed, 25 Jul 2018 12:28:27 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0

Follow-up Comment #2, bug #54373 (project octave):

The code for this is eventually some templates located in
liboctave/utils/oct-string.cc


template<typename T>
bool
octave::string::strncmp (const T& str_a, const T& str_b,
                         const typename T::size_type n)
{
  return (numel (str_a) >= n && numel (str_b) >= n
          && str_data_cmp<T> (str_a.data (), str_b.data (), n));
}

template<typename T>
bool
octave::string::strncmp (const T& str_a, const typename T::value_type *str_b,
                         const typename T::size_type n)
{
  return (numel (str_a) >= n && strlen<T> (str_b) >= n
          && str_data_cmp<T> (str_a.data (), str_b, n));
}


template<typename T>
bool
octave::string::strncmpi (const T& str_a, const T& str_b,
                          const typename T::size_type n)
{
  return (numel (str_a) >= n && numel (str_b) >= n
          && str_data_cmpi<T> (str_a.data (), str_b.data (), n));
}

template<typename T>
bool
octave::string::strncmpi (const T& str_a, const typename T::value_type
*str_b,
                          const typename T::size_type n)
{
  return (numel (str_a) >= n && strlen<T> (str_b) >= n
          && str_data_cmpi<T> (str_a.data (), str_b, n));
}


The simplest thing would simply be to remove the test on numel.  Otherwise,
one has to fiddle about determining what max N to use above.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54373>

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




reply via email to

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