summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/varlena.c
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1997-04-25 18:40:50 +0000
committerMarc G. Fournier <scrappy@hub.org>1997-04-25 18:40:50 +0000
commit094ec2d3f3d31a4dcd14945e8b0a3667c3103f0d (patch)
tree81e80a25191afa235fb74b901f96615dbf1aabbf /src/backend/utils/adt/varlena.c
parentb8e376ceb9a72c8d132e21699f11fe2b36b8c68c (diff)
downloadpostgresql-094ec2d3f3d31a4dcd14945e8b0a3667c3103f0d.tar.gz
More timezone patches by Thomas:
Here are patches which should help fix timezone problems in the datetime and abstime code. Also, I repatched varlena.c to add in some comments and a little error checking on top of Vadim's earlier repairs. There are slight mods to the circle data type to have the distance operator between circles measure the distance between closest points rather than between centers.
Diffstat (limited to 'src/backend/utils/adt/varlena.c')
-rw-r--r--src/backend/utils/adt/varlena.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index e5749cce0d..80ac9937ff 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.14 1997/04/21 04:31:53 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.15 1997/04/25 18:40:39 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -288,19 +288,23 @@ textne(struct varlena *arg1, struct varlena *arg2)
/* text_lt()
* Comparison function for text strings.
* Includes locale support, but must copy strings to temporary memory
- * to allow null-termination for inputs to strcoll().
+ * to allow null-termination for inputs to strcoll().
+ * XXX HACK code for textlen() indicates that there can be embedded nulls
+ * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
*/
bool
text_lt(struct varlena *arg1, struct varlena *arg2)
{
+ bool result;
+
+#ifdef USE_LOCALE
+ int cval;
+#endif
int len;
#ifdef UNSIGNED_CHAR_TEXT
unsigned
#endif
char *a1p, *a2p;
-#ifdef USE_LOCALE
- int cval;
-#endif
if (arg1 == NULL || arg2 == NULL)
return((bool) FALSE);
@@ -308,9 +312,11 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
#ifdef USE_LOCALE
-
- a1p = palloc (len+1);
- a2p = palloc (len+1);
+ if (!PointerIsValid(a1p = PALLOC(len+1))
+ || !PointerIsValid(a2p = PALLOC(len+1))) {
+ elog(WARN,"Unable to allocate memory for text comparison",NULL);
+ return(FALSE);
+ };
memcpy(a1p, VARDATA(arg1), len);
*(a1p+len) = '\0';
@@ -318,15 +324,11 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
*(a2p+len) = '\0';
cval = strcoll(a1p,a2p);
-
- pfree (a1p);
- pfree (a2p);
-
- return((bool) ( (cval < 0) ||
- ( (cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2)) ) ) );
+ result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2))));
+ PFREE(a1p);
+ PFREE(a2p);
#else
-
a1p = (unsigned char *)VARDATA(arg1);
a2p = (unsigned char *)VARDATA(arg2);
@@ -335,28 +337,33 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
a2p++;
len--;
};
- return((bool) (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2))));
+ result = (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2)));
#endif
+ return(result);
} /* text_lt() */
/* text_le()
* Comparison function for text strings.
* Includes locale support, but must copy strings to temporary memory
- * to allow null-termination for inputs to strcoll().
+ * to allow null-termination for inputs to strcoll().
+ * XXX HACK code for textlen() indicates that there can be embedded nulls
+ * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
*/
bool
text_le(struct varlena *arg1, struct varlena *arg2)
{
+ bool result;
+
+#ifdef USE_LOCALE
+ int cval;
+#endif
int len;
#ifdef UNSIGNED_CHAR_TEXT
unsigned
#endif
char *a1p, *a2p;
-#ifdef USE_LOCALE
- int cval;
-#endif
if (arg1 == NULL || arg2 == NULL)
return((bool) 0);
@@ -364,9 +371,11 @@ text_le(struct varlena *arg1, struct varlena *arg2)
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
#ifdef USE_LOCALE
-
- a1p = palloc (len+1);
- a2p = palloc (len+1);
+ if (!PointerIsValid(a1p = PALLOC(len+1))
+ || !PointerIsValid(a2p = PALLOC(len+1))) {
+ elog(WARN,"Unable to allocate memory for text comparison",NULL);
+ return(FALSE);
+ };
memcpy(a1p, VARDATA(arg1), len);
*(a1p+len) = '\0';
@@ -374,15 +383,11 @@ text_le(struct varlena *arg1, struct varlena *arg2)
*(a2p+len) = '\0';
cval = strcoll(a1p,a2p);
-
- pfree (a1p);
- pfree (a2p);
-
- return ((bool) ( (cval < 0) ||
- ( (cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2)) ) ) );
+ result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2))));
+ PFREE(a1p);
+ PFREE(a2p);
#else
-
a1p = (unsigned char *)VARDATA(arg1);
a2p = (unsigned char *)VARDATA(arg2);
@@ -392,10 +397,10 @@ text_le(struct varlena *arg1, struct varlena *arg2)
len--;
};
- return((bool) (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2))));
-
+ result = (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2)));
#endif
+ return(result);
} /* text_le() */
bool