bug-gnulib
[Top][All Lists]
Advanced

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

Re: test-xalloc-die note


From: Jim Meyering
Subject: Re: test-xalloc-die note
Date: Fri, 09 Apr 2010 20:57:22 +0200

Jim Meyering wrote:

> Jarno Rajahalme wrote:
>> Thanks for the instructions..
>>
>> OS: Darwin 10.3.0
>> tr: /usr/bin/tr
>> locale:
>> LANG=
>> LC_COLLATE="C"
>> LC_CTYPE="UTF-8"
>> LC_MESSAGES="C"
>> LC_MONETARY="C"
>> LC_NUMERIC="C"
>> LC_TIME="C"
>> LC_ALL=
>>
>> I get this kind of behavior both before and after the proposed patch:
>>
>> tests$ ./test-xalloc-die.sh
>> tr: Illegal byte sequence
> ...
>> I.e., most of the time tr complains, but not always.
>>
>> With set -x:
>>
>> tests$ ./test-xalloc-die.sh
> ...
>> ++ exec /bin/sh ./test-xalloc-die.sh --no-reexec
>> + . ./init.sh
> ...
>> ++++ rand_bytes_ 4
>> ++++ n_=4
>> ++++ chars_=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
>> ++++ dev_rand_=/dev/urandom
>> ++++ test -r /dev/urandom
>> ++++ dd ibs=4 count=1 if=/dev/urandom
>> ++++ tr -c abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 
>> 01234567abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
>> tr: Illegal byte sequence
>
> Thanks for the details.
> I suspect that this patch will solve it for you:
>
> diff --git a/tests/init.sh b/tests/init.sh
> index abfa3b3..64eb6f3 100644
> --- a/tests/init.sh
> +++ b/tests/init.sh
> @@ -259,7 +259,7 @@ rand_bytes_()
>    if test -r "$dev_rand_"; then
>      # Note: 256-length($chars_) == 194; 3 copies of $chars_ is 186 + 8 = 194.
>      dd ibs=$n_ count=1 if=$dev_rand_ 2>/dev/null \
> -      | tr -c $chars_ 01234567$chars_$chars_$chars_
> +      | LC_ALL=C tr -c $chars_ 01234567$chars_$chars_$chars_
>      return
>    fi

Actually there was one more.
The only other use of "tr" in init.sh is not susceptible.
Here's a better patch:

>From 6b8b58b99d6aaedeed12300cc154af7d3af7b95f Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 9 Apr 2010 20:53:49 +0200
Subject: [PATCH] init.sh: run tr in the "C" locale to avoid multibyte 
interpretation

* tests/init.sh (rand_bytes_): Run tr in the "C" locale so it does
not try to interpret its random input bytes.  Jarno Rajahalme reported
that ./test-xalloc-die.sh would fail with "tr: Illegal byte sequence"
on Darwin 10.3.0 with LC_CTYPE=UTF-8.
(mktempd_): Likewise, just in case.
---
 ChangeLog     |    7 +++++++
 tests/init.sh |    4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e6747aa..6c5122d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-04-09  Jim Meyering  <address@hidden>

+       init.sh: run tr in the "C" locale to avoid multibyte interpretation
+       * tests/init.sh (rand_bytes_): Run tr in the "C" locale so it does
+       not try to interpret its random input bytes.  Jarno Rajahalme reported
+       that ./test-xalloc-die.sh would fail with "tr: Illegal byte sequence".
+       on Darwin 10.3.0 with LC_CTYPE=UTF-8.
+       (mktempd_): Likewise, just in case.
+
        ftruncate: add two years to projected module removal date: 2012
        * m4/ftruncate.m4: Adjust comments.

diff --git a/tests/init.sh b/tests/init.sh
index abfa3b3..ee9c542 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -259,7 +259,7 @@ rand_bytes_()
   if test -r "$dev_rand_"; then
     # Note: 256-length($chars_) == 194; 3 copies of $chars_ is 186 + 8 = 194.
     dd ibs=$n_ count=1 if=$dev_rand_ 2>/dev/null \
-      | tr -c $chars_ 01234567$chars_$chars_$chars_
+      | LC_ALL=C tr -c $chars_ 01234567$chars_$chars_$chars_
     return
   fi

@@ -276,7 +276,7 @@ rand_bytes_()

   echo "$data_" \
     | dd bs=1 skip=50 count=$n_ 2>/dev/null \
-    | tr -c $chars_ 01234567$chars_$chars_$chars_
+    | LC_ALL=C tr -c $chars_ 01234567$chars_$chars_$chars_
 }

 mktempd_()
--
1.7.1.rc0.239.g8b27e




reply via email to

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