GNU bug report logs - #7203
[PATCH] sort: fix unportable conversion of unsigned char * -> char *

Previous Next

Package: coreutils;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Tue, 12 Oct 2010 20:09:02 UTC

Severity: normal

Tags: patch

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 7203 <at> debbugs.gnu.org
Subject: bug#7203: [PATCH] sort: fix unportable conversion of unsigned char * -> char *
Date: Tue, 12 Oct 2010 23:28:22 +0200
Paul Eggert wrote:
> This is another portability bug caught by the Sun C compiler.
> Without this patch, cc complains:
>
> "sort.c", line 3933: warning: assignment type mismatch:
>         pointer to const char "=" pointer to unsigned char
>
>
> * src/sort.c (fold_toupper): Change this back from char to
> unsigned char, fixing a regression introduced in commit
> 59e2e55d0f154a388adc9bac37d2b45f2ba971f8 dated February 26, as the
> C Standard doesn't let you convert from unsigned char * to char *
> without a cast, and the (in theory more portable) style here is to
> convert char values, not pointer values.
> (getmonth): Convert char to unsigned char when needed for
> comparison.

Calling commit 59e2e55d0f a regression might lead the unwary
to think that it causes sort to malfunction, when in fact,
at worst (afaics), it evokes a warning.

So how about something like s/regression/problem/ ?

This feels like enough of a technicality that I'd prefer to defer it.

> ---
>  src/sort.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/sort.c b/src/sort.c
> index 89f7be3..c155eda 100644
> --- a/src/sort.c
> +++ b/src/sort.c
> @@ -268,7 +268,7 @@ static bool nonprinting[UCHAR_LIM];
>  static bool nondictionary[UCHAR_LIM];
>
>  /* Translation table folding lower case to upper.  */
> -static unsigned char fold_toupper[UCHAR_LIM];
> +static char fold_toupper[UCHAR_LIM];
>
>  #define MONTHS_PER_YEAR 12
>
> @@ -1952,12 +1952,12 @@ getmonth (char const *month, char **ea)
>                  *ea = (char *) m;
>                return monthtab[ix].val;
>              }
> -          if (fold_toupper[to_uchar (*m)] < to_uchar (*n))
> +          if (to_uchar (fold_toupper[to_uchar (*m)]) < to_uchar (*n))
>              {
>                hi = ix;
>                break;
>              }
> -          else if (fold_toupper[to_uchar (*m)] > to_uchar (*n))
> +          else if (to_uchar (fold_toupper[to_uchar (*m)]) > to_uchar (*n))
>              {
>                lo = ix + 1;
>                break;




This bug report was last modified 14 years and 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.