Skip to content

Commit

Permalink
* string/Makefile (tests): Add tst-strxfrm2.
Browse files Browse the repository at this point in the history
	* string/tst-strxfrm2.c: New file.

	* string/strxfrm_l.c (STRXFRM): Do the trailing \1 removal
	optimization even if needed > n.
  • Loading branch information
Ulrich Drepper committed Nov 9, 2006
1 parent 2692dee commit 2f334ad
Showing 4 changed files with 59 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
2006-11-09 Ulrich Drepper <drepper@redhat.com>

* string/Makefile (tests): Add tst-strxfrm2.
* string/tst-strxfrm2.c: New file.

2006-10-09 Jakub Jelinek <jakub@redhat.com>

* elf/dl-debug.c (_dl_debug_initialize): Check r->r_map for 0
rather than r->r_brk.

2006-11-08 Jakub Jelinek <jakub@redhat.com>

* string/strxfrm_l.c (STRXFRM): Do the trailing \1 removal
optimization even if needed > n.

* elf/dl-load.c (decompose_rpath): Return bool rather than void.
If l->l_name is on inhibit_rpath list, set sps->dirs to -1 and
return false, otherwise return true.
2 changes: 1 addition & 1 deletion string/Makefile
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ tests := tester inl-tester noinl-tester testcopy test-ffs \
bug-strncat1 bug-strspn1 bug-strpbrk1 tst-bswap \
tst-strtok tst-strxfrm bug-strcoll1 tst-strfry \
bug-strtok1 $(addprefix test-,$(strop-tests)) \
bug-envz1
bug-envz1 tst-strxfrm2
distribute := memcopy.h pagecopy.h tst-svc.expect test-string.h


11 changes: 7 additions & 4 deletions string/strxfrm_l.c
Original file line number Diff line number Diff line change
@@ -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. */
43 changes: 43 additions & 0 deletions string/tst-strxfrm2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <locale.h>
#include <stdio.h>
#include <string.h>

static int
do_test (void)
{
int res = 0;

char buf[10];
size_t l1 = strxfrm (NULL, "ab", 0);
size_t l2 = strxfrm (buf, "ab", 1);
size_t l3 = strxfrm (buf, "ab", sizeof (buf));

if (l1 != l2 || l1 != l3)
{
puts ("C locale test failed");
res = 1;
}

if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
{
puts ("setlocale failed");
res = 1;
}
else
{
l1 = strxfrm (NULL, "ab", 0);
l2 = strxfrm (buf, "ab", 1);
l3 = strxfrm (buf, "ab", sizeof (buf));

if (l1 != l2 || l1 != l3)
{
puts ("UTF-8 locale test failed");
res = 1;
}
}

return res;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

0 comments on commit 2f334ad

Please sign in to comment.