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

Commitcccbdde

Browse files
committed
Be more careful about signed vs. unsigned char
The buildfarm has reminded me that not all systems consider char to besigned and we need to be explicit. Adjust the various bits of mac8.cfor what we intend, mostly using casts to unsigned char as suggested byTom, and adjust the tests for valid input accordingly. Explicitly makethe hexlookup table signed as it's useful to use -1 there to indicate aninvalid value.
1 parent7821f72 commitcccbdde

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 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,constchar*ptr);
38+
staticunsignedcharhex2_to_uchar(constunsignedchar*str,constunsignedchar*ptr);
3939

40-
staticconstcharhexlookup[128]= {
40+
staticconstsignedcharhexlookup[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,
@@ -58,16 +58,16 @@ static const char hexlookup[128] = {
5858
* the entire string, which is used only for error reporting.
5959
*/
6060
staticinlineunsignedchar
61-
hex2_to_uchar(constchar*ptr,constchar*str)
61+
hex2_to_uchar(constunsignedchar*ptr,constunsignedchar*str)
6262
{
6363
unsignedcharret=0;
64-
charlookup;
64+
signedcharlookup;
6565

6666
/* Handle the first character */
67-
if (*ptr<0)
67+
if (*ptr>127)
6868
gotoinvalid_input;
6969

70-
lookup=hexlookup[(unsignedchar)*ptr];
70+
lookup=hexlookup[*ptr];
7171
if (lookup<0)
7272
gotoinvalid_input;
7373

@@ -76,10 +76,10 @@ hex2_to_uchar(const char *ptr, const char *str)
7676
/* Move to the second character */
7777
ptr++;
7878

79-
if (*ptr<0)
79+
if (*ptr>127)
8080
gotoinvalid_input;
8181

82-
lookup=hexlookup[(unsignedchar)*ptr];
82+
lookup=hexlookup[*ptr];
8383
if (lookup<0)
8484
gotoinvalid_input;
8585

@@ -103,8 +103,8 @@ hex2_to_uchar(const char *ptr, const char *str)
103103
Datum
104104
macaddr8_in(PG_FUNCTION_ARGS)
105105
{
106-
constchar*str=PG_GETARG_CSTRING(0);
107-
constchar*ptr=str;
106+
constunsignedchar*str= (unsignedchar*)PG_GETARG_CSTRING(0);
107+
constunsignedchar*ptr=str;
108108
macaddr8*result;
109109
unsignedchara=0,
110110
b=0,
@@ -115,10 +115,10 @@ macaddr8_in(PG_FUNCTION_ARGS)
115115
g=0,
116116
h=0;
117117
intcount=0;
118-
charspacer='\0';
118+
unsignedcharspacer='\0';
119119

120120
/* skip leading spaces */
121-
while (*ptr&&isspace((unsignedchar)*ptr))
121+
while (*ptr&&isspace(*ptr))
122122
ptr++;
123123

124124
/* digits must always come in pairs */
@@ -191,9 +191,9 @@ macaddr8_in(PG_FUNCTION_ARGS)
191191
/* allow trailing whitespace after if we have 6 or 8 bytes */
192192
if (count==6||count==8)
193193
{
194-
if (isspace((unsignedchar)*ptr))
194+
if (isspace(*ptr))
195195
{
196-
while (*++ptr&&isspace((unsignedchar)*ptr));
196+
while (*++ptr&&isspace(*ptr));
197197

198198
/* If we found a space and then non-space, it's invalid */
199199
if (*ptr)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp