Skip to content

Commit 9f42a56

Browse files
committed
Fix for text_lt/text_le to avoid warnings if not def USE_LOCALE.
1 parent 42e7250 commit 9f42a56

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/backend/utils/adt/varlena.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.13 1997/04/09 08:29:35 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.14 1997/04/21 04:31:53 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -288,47 +288,45 @@ textne(struct varlena *arg1, struct varlena *arg2)
288288
/* text_lt()
289289
* Comparison function for text strings.
290290
* Includes locale support, but must copy strings to temporary memory
291-
* to allow null-termination for inputs to strcoll().
292-
* XXX HACK code for textlen() indicates that there can be embedded nulls
293-
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
291+
* to allow null-termination for inputs to strcoll().
294292
*/
295293
bool
296294
text_lt(struct varlena *arg1, struct varlena *arg2)
297295
{
298-
bool result;
299-
300-
int cval;
301296
int len;
302297
#ifdef UNSIGNED_CHAR_TEXT
303298
unsigned
304299
#endif
305300
char *a1p, *a2p;
301+
#ifdef USE_LOCALE
302+
int cval;
303+
#endif
306304

307305
if (arg1 == NULL || arg2 == NULL)
308306
return((bool) FALSE);
309307

310308
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
311309

312310
#ifdef USE_LOCALE
313-
if (!PointerIsValid(a1p = PALLOC(len+1))
314-
|| !PointerIsValid(a2p = PALLOC(len+1))) {
315-
elog(WARN,"Unable to allocate memory for text comparison",NULL);
316-
return(FALSE);
317-
};
311+
312+
a1p = palloc (len+1);
313+
a2p = palloc (len+1);
318314

319315
memcpy(a1p, VARDATA(arg1), len);
320316
*(a1p+len) = '\0';
321317
memcpy(a2p, VARDATA(arg2), len);
322318
*(a2p+len) = '\0';
323319

324320
cval = strcoll(a1p,a2p);
325-
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2))));
321+
322+
pfree (a1p);
323+
pfree (a2p);
326324

327-
PFREE(a1p);
328-
PFREE(a2p);
325+
return((bool) ( (cval < 0) ||
326+
( (cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2)) ) ) );
329327

330-
return(result);
331328
#else
329+
332330
a1p = (unsigned char *)VARDATA(arg1);
333331
a2p = (unsigned char *)VARDATA(arg2);
334332

@@ -338,53 +336,53 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
338336
len--;
339337
};
340338
return((bool) (len? (*a1p < *a2p): (VARSIZE(arg1) < VARSIZE(arg2))));
339+
341340
#endif
341+
342342
} /* text_lt() */
343343

344344
/* text_le()
345345
* Comparison function for text strings.
346346
* Includes locale support, but must copy strings to temporary memory
347-
* to allow null-termination for inputs to strcoll().
348-
* XXX HACK code for textlen() indicates that there can be embedded nulls
349-
* but it appears that most routines (incl. this one) assume not! - tgl 97/04/07
347+
* to allow null-termination for inputs to strcoll().
350348
*/
351349
bool
352350
text_le(struct varlena *arg1, struct varlena *arg2)
353351
{
354-
bool result;
355-
356-
int cval;
357352
int len;
358353
#ifdef UNSIGNED_CHAR_TEXT
359354
unsigned
360355
#endif
361356
char *a1p, *a2p;
357+
#ifdef USE_LOCALE
358+
int cval;
359+
#endif
362360

363361
if (arg1 == NULL || arg2 == NULL)
364362
return((bool) 0);
365363

366364
len = (((VARSIZE(arg1) <= VARSIZE(arg2))? VARSIZE(arg1): VARSIZE(arg2))-VARHDRSZ);
367365

368366
#ifdef USE_LOCALE
369-
if (!PointerIsValid(a1p = PALLOC(len+1))
370-
|| !PointerIsValid(a2p = PALLOC(len+1))) {
371-
elog(WARN,"Unable to allocate memory for text comparison",NULL);
372-
return(FALSE);
373-
};
367+
368+
a1p = palloc (len+1);
369+
a2p = palloc (len+1);
374370

375371
memcpy(a1p, VARDATA(arg1), len);
376372
*(a1p+len) = '\0';
377373
memcpy(a2p, VARDATA(arg2), len);
378374
*(a2p+len) = '\0';
379375

380376
cval = strcoll(a1p,a2p);
381-
result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2))));
377+
378+
pfree (a1p);
379+
pfree (a2p);
382380

383-
PFREE(a1p);
384-
PFREE(a2p);
381+
return ((bool) ( (cval < 0) ||
382+
( (cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2)) ) ) );
385383

386-
return(result);
387384
#else
385+
388386
a1p = (unsigned char *)VARDATA(arg1);
389387
a2p = (unsigned char *)VARDATA(arg2);
390388

@@ -395,7 +393,9 @@ text_le(struct varlena *arg1, struct varlena *arg2)
395393
};
396394

397395
return((bool) (len? (*a1p <= *a2p): (VARSIZE(arg1) <= VARSIZE(arg2))));
396+
398397
#endif
398+
399399
} /* text_le() */
400400

401401
bool

0 commit comments

Comments
 (0)