[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/
- [Octave-bug-tracker] [bug #54373] Different behavior of strncmp compared to Matlab, Arnaud Delorme, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length,
Rik <=
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Philip Nienhuis, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/25
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/27
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Philip Nienhuis, 2018/07/27
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/27
- [Octave-bug-tracker] [bug #54373] strncmp does not compute result accurately when N exceeds string length, Rik, 2018/07/28