diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-11-09 20:20:23 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-11-09 20:20:23 +0000 |
commit | 2f334ad5c3c1510f5dc6b0a1ecebba2168effba7 (patch) | |
tree | 461d1406a5378e0dbbf7ea7c536ce13115b63c7d /string/strxfrm_l.c | |
parent | 2692deea65f13becedc2ce283fbc97a3c139f165 (diff) | |
download | glibc-2f334ad5c3c1510f5dc6b0a1ecebba2168effba7.tar glibc-2f334ad5c3c1510f5dc6b0a1ecebba2168effba7.tar.gz glibc-2f334ad5c3c1510f5dc6b0a1ecebba2168effba7.tar.bz2 glibc-2f334ad5c3c1510f5dc6b0a1ecebba2168effba7.zip |
* string/Makefile (tests): Add tst-strxfrm2.
* string/tst-strxfrm2.c: New file.
* string/strxfrm_l.c (STRXFRM): Do the trailing \1 removal
optimization even if needed > n.
Diffstat (limited to 'string/strxfrm_l.c')
-rw-r--r-- | string/strxfrm_l.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/string/strxfrm_l.c b/string/strxfrm_l.c index 5335601919..f158833f05 100644 --- a/string/strxfrm_l.c +++ b/string/strxfrm_l.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1995,96,97,2002, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1995, 1996, 1997, 2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@gnu.org>, 1995. @@ -96,6 +97,7 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) const int32_t *indirect; uint_fast32_t pass; size_t needed; + size_t last_needed; const USTRING_TYPE *usrc; size_t srclen = STRLEN (src); int32_t *idxarr; @@ -197,6 +199,7 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) this is true for all of them. */ int position = rule & sort_position; + last_needed = needed; if (position == 0) { for (idxcnt = 0; idxcnt < idxmax; ++idxcnt) @@ -426,11 +429,11 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) a `position' rule at the end and if no non-ignored character is found the last \1 byte is immediately followed by a \0 byte signalling this. We can avoid the \1 byte(s). */ - if (needed <= n && needed > 2 && dest[needed - 2] == L('\1')) + if (needed > 2 && needed == last_needed + 1) { /* Remove the \1 byte. */ - --needed; - dest[needed - 1] = L('\0'); + if (--needed < n) + dest[needed - 1] = L('\0'); } /* Free the memory if needed. */ |