From f2f53aee0f2810a935e0f86b17f8dedba3647da0 Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Tue, 10 Sep 1996 06:41:38 +0000 Subject: [PATCH] Fixes: The comparison routines for text and char data type give incorrect results if the input data contains characters greater than 127. As these routines perform the comparison using signed char variables all character codes greater than 127 are interpreted as less than 0. These codes are used to encode the iso8859 char sets. The other text-like data types seem to work as expected as they use unsigned chars in comparisons. Submitted by: Massimo Dal Zotto --- src/backend/utils/adt/char.c | 9 ++++++++- src/backend/utils/adt/varlena.c | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/char.c b/src/backend/utils/adt/char.c index 0d9c8f4fb5..04508129cf 100644 --- a/src/backend/utils/adt/char.c +++ b/src/backend/utils/adt/char.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.1.1.1 1996/07/09 06:22:03 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.2 1996/09/10 06:41:34 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -129,10 +129,17 @@ char *char16out(char *s) int32 chareq(int8 arg1, int8 arg2) { return(arg1 == arg2); } int32 charne(int8 arg1, int8 arg2) { return(arg1 != arg2); } +#ifdef UNSIGNED_CHAR_TEXT +int32 charlt(int8 arg1, int8 arg2) { return((uint8)arg1 < (uint8)arg2); } +int32 charle(int8 arg1, int8 arg2) { return((uint8)arg1 <= (uint8)arg2); } +int32 chargt(int8 arg1, int8 arg2) { return((uint8)arg1 > (uint8)arg2); } +int32 charge(int8 arg1, int8 arg2) { return((uint8)arg1 >= (uint8)arg2); } +#else int32 charlt(int8 arg1, int8 arg2) { return(arg1 < arg2); } int32 charle(int8 arg1, int8 arg2) { return(arg1 <= arg2); } int32 chargt(int8 arg1, int8 arg2) { return(arg1 > arg2); } int32 charge(int8 arg1, int8 arg2) { return(arg1 >= arg2); } +#endif int8 charpl(int8 arg1, int8 arg2) { return(arg1 + arg2); } int8 charmi(int8 arg1, int8 arg2) { return(arg1 - arg2); } int8 charmul(int8 arg1, int8 arg2) { return(arg1 * arg2); } diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index a00528eff1..3f95681293 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.4 1996/07/22 21:56:04 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.5 1996/09/10 06:41:38 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -290,6 +290,9 @@ int32 text_lt(struct varlena *arg1, struct varlena *arg2) { int len; +#ifdef UNSIGNED_CHAR_TEXT + unsigned +#endif char *a1p, *a2p; if (arg1 == NULL || arg2 == NULL) @@ -318,6 +321,9 @@ int32 text_le(struct varlena *arg1, struct varlena *arg2) { int len; +#ifdef UNSIGNED_CHAR_TEXT + unsigned +#endif char *a1p, *a2p; if (arg1 == NULL || arg2 == NULL)