mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Suppress compiler warnings about useless comparison of unsigned to zero.
Reportedly, some compilers warn about tests like "c < 0" if c is unsigned, and hence complain about the character range checks I added in commit 3bb3f42f3749d40b8d4de65871e8d828b18d4a45. This is a bit of a pain since the regex library doesn't really want to assume that chr is unsigned. However, since any such reconfiguration would involve manual edits of regcustom.h anyway, we can put it on the shoulders of whoever wants to do that to adjust this new range-checking macro correctly. Per gripes from Coverity and Andres.
This commit is contained in:
parent
2dcaebea07
commit
d2ab9b0ac3
@ -792,13 +792,13 @@ lexescape(struct vars * v)
|
|||||||
break;
|
break;
|
||||||
case CHR('u'):
|
case CHR('u'):
|
||||||
c = lexdigits(v, 16, 4, 4);
|
c = lexdigits(v, 16, 4, 4);
|
||||||
if (ISERR() || c < CHR_MIN || c > CHR_MAX)
|
if (ISERR() || !CHR_IS_IN_RANGE(c))
|
||||||
FAILW(REG_EESCAPE);
|
FAILW(REG_EESCAPE);
|
||||||
RETV(PLAIN, c);
|
RETV(PLAIN, c);
|
||||||
break;
|
break;
|
||||||
case CHR('U'):
|
case CHR('U'):
|
||||||
c = lexdigits(v, 16, 8, 8);
|
c = lexdigits(v, 16, 8, 8);
|
||||||
if (ISERR() || c < CHR_MIN || c > CHR_MAX)
|
if (ISERR() || !CHR_IS_IN_RANGE(c))
|
||||||
FAILW(REG_EESCAPE);
|
FAILW(REG_EESCAPE);
|
||||||
RETV(PLAIN, c);
|
RETV(PLAIN, c);
|
||||||
break;
|
break;
|
||||||
@ -816,7 +816,7 @@ lexescape(struct vars * v)
|
|||||||
case CHR('x'):
|
case CHR('x'):
|
||||||
NOTE(REG_UUNPORT);
|
NOTE(REG_UUNPORT);
|
||||||
c = lexdigits(v, 16, 1, 255); /* REs >255 long outside spec */
|
c = lexdigits(v, 16, 1, 255); /* REs >255 long outside spec */
|
||||||
if (ISERR() || c < CHR_MIN || c > CHR_MAX)
|
if (ISERR() || !CHR_IS_IN_RANGE(c))
|
||||||
FAILW(REG_EESCAPE);
|
FAILW(REG_EESCAPE);
|
||||||
RETV(PLAIN, c);
|
RETV(PLAIN, c);
|
||||||
break;
|
break;
|
||||||
|
@ -68,6 +68,17 @@ typedef int celt; /* type to hold chr, or NOCELT */
|
|||||||
#define CHR_MAX 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and
|
#define CHR_MAX 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and
|
||||||
* CHR_MAX+1 must fit in both chr and celt */
|
* CHR_MAX+1 must fit in both chr and celt */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if a chr value is in range. Ideally we'd just write this as
|
||||||
|
* ((c) >= CHR_MIN && (c) <= CHR_MAX)
|
||||||
|
* However, if chr is unsigned and CHR_MIN is zero, the first part of that
|
||||||
|
* is a no-op, and certain overly-nannyish compilers give warnings about it.
|
||||||
|
* So we leave that out here. If you want to make chr signed and/or CHR_MIN
|
||||||
|
* not zero, redefine this macro as above. Callers should assume that the
|
||||||
|
* macro may multiply evaluate its argument, even though it does not today.
|
||||||
|
*/
|
||||||
|
#define CHR_IS_IN_RANGE(c) ((c) <= CHR_MAX)
|
||||||
|
|
||||||
/* functions operating on chr */
|
/* functions operating on chr */
|
||||||
#define iscalnum(x) pg_wc_isalnum(x)
|
#define iscalnum(x) pg_wc_isalnum(x)
|
||||||
#define iscalpha(x) pg_wc_isalpha(x)
|
#define iscalpha(x) pg_wc_isalpha(x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user