Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3ad502

Browse files
committed
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 commit3bb3f42. This is a bit of a pain sincethe regex library doesn't really want to assume that chr is unsigned.However, since any such reconfiguration would involve manual edits ofregcustom.h anyway, we can put it on the shoulders of whoever wants todo that to adjust this new range-checking macro correctly.Per gripes from Coverity and Andres.
1 parent4492ab5 commite3ad502

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

‎src/backend/regex/regc_lex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,13 @@ lexescape(struct vars * v)
792792
break;
793793
caseCHR('u'):
794794
c=lexdigits(v,16,4,4);
795-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
795+
if (ISERR()||!CHR_IS_IN_RANGE(c))
796796
FAILW(REG_EESCAPE);
797797
RETV(PLAIN,c);
798798
break;
799799
caseCHR('U'):
800800
c=lexdigits(v,16,8,8);
801-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
801+
if (ISERR()||!CHR_IS_IN_RANGE(c))
802802
FAILW(REG_EESCAPE);
803803
RETV(PLAIN,c);
804804
break;
@@ -816,7 +816,7 @@ lexescape(struct vars * v)
816816
caseCHR('x'):
817817
NOTE(REG_UUNPORT);
818818
c=lexdigits(v,16,1,255);/* REs >255 long outside spec */
819-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
819+
if (ISERR()||!CHR_IS_IN_RANGE(c))
820820
FAILW(REG_EESCAPE);
821821
RETV(PLAIN,c);
822822
break;

‎src/include/regex/regcustom.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ typedef int celt;/* type to hold chr, or NOCELT */
6868
#defineCHR_MAX 0x7ffffffe/* CHR_MAX-CHR_MIN+1 must fit in an int, and
6969
* CHR_MAX+1 must fit in both chr and celt */
7070

71+
/*
72+
* Check if a chr value is in range. Ideally we'd just write this as
73+
*((c) >= CHR_MIN && (c) <= CHR_MAX)
74+
* However, if chr is unsigned and CHR_MIN is zero, the first part of that
75+
* is a no-op, and certain overly-nannyish compilers give warnings about it.
76+
* So we leave that out here. If you want to make chr signed and/or CHR_MIN
77+
* not zero, redefine this macro as above. Callers should assume that the
78+
* macro may multiply evaluate its argument, even though it does not today.
79+
*/
80+
#defineCHR_IS_IN_RANGE(c)((c) <= CHR_MAX)
81+
7182
/* functions operating on chr */
7283
#defineiscalnum(x) pg_wc_isalnum(x)
7384
#defineiscalpha(x) pg_wc_isalpha(x)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp