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

Commit7821f72

Browse files
committed
Clean up overly paranoid checks in mac8.c
Andres' compiler points out, quite correctly, that there's no need forsome of the overly paranoid checks which were put into mac8.c. Removethose, as they're useless, add some comments and make a few other minorimprovements- reduce the size of hexlookup by making it a char arrayinstead of an int array, and pass in the ptr location directly insteadof making hex2_to_uchar re-calculate the location based off the offsetevery time.
1 parent6977b8b commit7821f72

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

‎src/backend/utils/adt/mac8.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
#definelobits(addr) \
3636
((unsigned long)(((addr)->e<<24) | ((addr)->f<<16) | ((addr)->g<<8) | ((addr)->h)))
3737

38-
staticunsignedcharhex2_to_uchar(constchar*str,intoffset);
38+
staticunsignedcharhex2_to_uchar(constchar*str,constchar*ptr);
3939

40-
staticconstinthexlookup[128]= {
40+
staticconstcharhexlookup[128]= {
4141
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
4242
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
4343
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@@ -48,31 +48,39 @@ static const int hexlookup[128] = {
4848
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
4949
};
5050

51+
/*
52+
* hex2_to_uchar - convert 2 hex digits to a byte (unsigned char)
53+
*
54+
* This will ereport() if the end of the string is reached ('\0' found), or if
55+
* either character is not a valid hex digit.
56+
*
57+
* ptr is the pointer to where the digits to convert are in the string, str is
58+
* the entire string, which is used only for error reporting.
59+
*/
5160
staticinlineunsignedchar
52-
hex2_to_uchar(constchar*str,intoffset)
61+
hex2_to_uchar(constchar*ptr,constchar*str)
5362
{
5463
unsignedcharret=0;
55-
intlookup;
56-
constchar*ptr=str+offset;
64+
charlookup;
5765

5866
/* Handle the first character */
59-
if (*ptr<0||*ptr >=127)
67+
if (*ptr<0)
6068
gotoinvalid_input;
6169

6270
lookup=hexlookup[(unsignedchar)*ptr];
63-
if (lookup<0||lookup>15)
71+
if (lookup<0)
6472
gotoinvalid_input;
6573

6674
ret=lookup <<4;
6775

6876
/* Move to the second character */
6977
ptr++;
7078

71-
if (*ptr<0||*ptr>127)
79+
if (*ptr<0)
7280
gotoinvalid_input;
7381

7482
lookup=hexlookup[(unsignedchar)*ptr];
75-
if (lookup<0||lookup>15)
83+
if (lookup<0)
7684
gotoinvalid_input;
7785

7886
ret+=lookup;
@@ -128,28 +136,28 @@ macaddr8_in(PG_FUNCTION_ARGS)
128136
switch (count)
129137
{
130138
case1:
131-
a=hex2_to_uchar(str,ptr-str);
139+
a=hex2_to_uchar(ptr,str);
132140
break;
133141
case2:
134-
b=hex2_to_uchar(str,ptr-str);
142+
b=hex2_to_uchar(ptr,str);
135143
break;
136144
case3:
137-
c=hex2_to_uchar(str,ptr-str);
145+
c=hex2_to_uchar(ptr,str);
138146
break;
139147
case4:
140-
d=hex2_to_uchar(str,ptr-str);
148+
d=hex2_to_uchar(ptr,str);
141149
break;
142150
case5:
143-
e=hex2_to_uchar(str,ptr-str);
151+
e=hex2_to_uchar(ptr,str);
144152
break;
145153
case6:
146-
f=hex2_to_uchar(str,ptr-str);
154+
f=hex2_to_uchar(ptr,str);
147155
break;
148156
case7:
149-
g=hex2_to_uchar(str,ptr-str);
157+
g=hex2_to_uchar(ptr,str);
150158
break;
151159
case8:
152-
h=hex2_to_uchar(str,ptr-str);
160+
h=hex2_to_uchar(ptr,str);
153161
break;
154162
default:
155163
/* must be trailing garbage... */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp