summaryrefslogtreecommitdiff
path: root/gnu/lib/libg++/libstdc++/std
diff options
context:
space:
mode:
authorphil <phil@NetBSD.org>1996-12-17 18:55:08 +0000
committerphil <phil@NetBSD.org>1996-12-17 18:55:08 +0000
commit1496ef1851bd95279a6c0eae83218e7512c414c8 (patch)
tree202eeb07e282ee89038c2cbeb94f56ace5696803 /gnu/lib/libg++/libstdc++/std
parent1460fbef53f4978617338a8c46f435a648572ca9 (diff)
Import of libg++ 2.7.2.
Diffstat (limited to 'gnu/lib/libg++/libstdc++/std')
-rw-r--r--gnu/lib/libg++/libstdc++/std/bastring.cc14
-rw-r--r--gnu/lib/libg++/libstdc++/std/bastring.h12
2 files changed, 16 insertions, 10 deletions
diff --git a/gnu/lib/libg++/libstdc++/std/bastring.cc b/gnu/lib/libg++/libstdc++/std/bastring.cc
index d3317c50084..92c69d845b2 100644
--- a/gnu/lib/libg++/libstdc++/std/bastring.cc
+++ b/gnu/lib/libg++/libstdc++/std/bastring.cc
@@ -86,7 +86,7 @@ template <class charT, class traits>
inline bool basic_string <charT, traits>::
check_realloc (size_t s) const
{
- ++s;
+ s += sizeof (charT);
return (rep ()->ref > 1
|| s > capacity ()
|| Rep::excess_slop (s, capacity ()));
@@ -154,7 +154,7 @@ replace (size_t pos, size_t n1, const charT* s, size_t n2)
OUTOFRANGE (pos > len);
if (n1 > len - pos)
n1 = len - pos;
- LENGTHERROR (len - n1 >= npos - n2);
+ LENGTHERROR (len - n1 > max_size () - n2);
size_t newlen = len - n1 + n2;
if (check_realloc (newlen))
@@ -190,7 +190,7 @@ replace (size_t pos, size_t n1, size_t n2, charT c)
OUTOFRANGE (pos > len);
if (n1 > len - pos)
n1 = len - pos;
- LENGTHERROR (len - n1 >= npos - n2);
+ LENGTHERROR (len - n1 > max_size () - n2);
size_t newlen = len - n1 + n2;
if (check_realloc (newlen))
@@ -215,7 +215,7 @@ template <class charT, class traits>
void basic_string <charT, traits>::
resize (size_t n, charT c)
{
- LENGTHERROR (n == npos);
+ LENGTHERROR (n > max_size ());
if (n > length ())
append (n - length (), c);
@@ -269,6 +269,9 @@ template <class charT, class traits>
size_t basic_string <charT, traits>::
rfind (const charT* s, size_t pos, size_t n) const
{
+ if (n > length ())
+ return npos;
+
size_t xpos = length () - n;
if (xpos > pos)
xpos = pos;
@@ -284,6 +287,9 @@ template <class charT, class traits>
size_t basic_string <charT, traits>::
rfind (charT c, size_t pos) const
{
+ if (1 > length ())
+ return npos;
+
size_t xpos = length () - 1;
if (xpos > pos)
xpos = pos;
diff --git a/gnu/lib/libg++/libstdc++/std/bastring.h b/gnu/lib/libg++/libstdc++/std/bastring.h
index 6361ef27cca..d6174a21f92 100644
--- a/gnu/lib/libg++/libstdc++/std/bastring.h
+++ b/gnu/lib/libg++/libstdc++/std/bastring.h
@@ -139,7 +139,7 @@ public:
size_type capacity () const
{ return rep ()->res; }
size_type max_size () const
- { return npos - 1; } // XXX
+ { return (npos - 1)/sizeof (charT); } // XXX
bool empty () const
{ return size () == 0; }
@@ -221,20 +221,20 @@ public:
basic_string& insert (size_type pos, size_type n, charT c)
{ return replace (pos, 0, n, c); }
iterator insert(iterator p, charT c)
- { insert (p - begin (), 1, c); return p; }
+ { size_type pos = p - begin (); insert (pos, 1, c); return pos +begin (); }
iterator insert(iterator p, size_type n, charT c)
- { insert (p - begin (), n, c); return p; }
+ { size_type pos = p - begin (); insert (pos, n, c); return pos +begin (); }
#if 0
template<class InputIterator>
void insert(iterator p, InputIterator first, InputIterator last);
#endif
basic_string& remove (size_type pos = 0, size_type n = npos)
- { return replace (pos, n, 0, (charT)0); }
+ { return replace (pos, n, (size_type)0, (charT)0); }
basic_string& remove (iterator pos)
- { return replace (pos - begin (), 1, 0, (charT)0); }
+ { return replace (pos - begin (), 1, (size_type)0, (charT)0); }
basic_string& remove (iterator first, iterator last)
- { return replace (first - begin (), last - first, 0, (charT)0); }
+ { return replace (first - begin (), last - first, (size_type)0, (charT)0);}
basic_string& replace (size_type pos1, size_type n1, const basic_string& str,
size_type pos2 = 0, size_type n2 = npos);