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

Commit8c95ae8

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 parentdb76b1e commit8c95ae8

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
@@ -813,13 +813,13 @@ lexescape(struct vars * v)
813813
break;
814814
caseCHR('u'):
815815
c=lexdigits(v,16,4,4);
816-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
816+
if (ISERR()||!CHR_IS_IN_RANGE(c))
817817
FAILW(REG_EESCAPE);
818818
RETV(PLAIN,c);
819819
break;
820820
caseCHR('U'):
821821
c=lexdigits(v,16,8,8);
822-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
822+
if (ISERR()||!CHR_IS_IN_RANGE(c))
823823
FAILW(REG_EESCAPE);
824824
RETV(PLAIN,c);
825825
break;
@@ -837,7 +837,7 @@ lexescape(struct vars * v)
837837
caseCHR('x'):
838838
NOTE(REG_UUNPORT);
839839
c=lexdigits(v,16,1,255);/* REs >255 long outside spec */
840-
if (ISERR()||c<CHR_MIN||c>CHR_MAX)
840+
if (ISERR()||!CHR_IS_IN_RANGE(c))
841841
FAILW(REG_EESCAPE);
842842
RETV(PLAIN,c);
843843
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