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

Commit4212179

Browse files
committed
Change pqformat.h's integer handling functions to take unsigned integers.
As added in1de09ad the new functionsall accept signed integers as parameters. That's not great, becauseit's perfectly reasonable to call them with unsigned parameters.Unfortunately unsigned to signed conversion is not well defined, whenexceeding the range of the signed value. That's presently not apractical issue in postgres (among other reasons because we forcegcc's hand with -fwrapv). But it's clearly not quite right.Thus change the signatures to accept unsigned integers instead, signedto unsigned conversion is always well defined. Also change thebackward compat pq_sendint() - while it's deprecated it seems betterto be consistent.Per discussion between Andrew Gierth, Michael Paquier, Alvaro Herreraand Tom Lane.Reported-By: Andrew GierthAuthor: Andres FreundDiscussion:https://postgr.es/m/87r2m10zm2.fsf@news-spur.riddles.org.uk
1 parent9860708 commit4212179

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

‎src/include/libpq/pqformat.h

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern void pq_sendfloat4(StringInfo buf, float4 f);
3535
externvoidpq_sendfloat8(StringInfobuf,float8f);
3636

3737
/*
38-
* Appendanint8 to a StringInfo buffer, which already has enough space
38+
* Appenda [u]int8 to a StringInfo buffer, which already has enough space
3939
* preallocated.
4040
*
4141
* The use of pg_restrict allows the compiler to optimize the code based on
@@ -47,55 +47,55 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
4747
* overly picky and demanding a * before a restrict.
4848
*/
4949
staticinlinevoid
50-
pq_writeint8(StringInfoData*pg_restrictbuf,int8i)
50+
pq_writeint8(StringInfoData*pg_restrictbuf,uint8i)
5151
{
52-
int8ni=i;
52+
uint8ni=i;
5353

54-
Assert(buf->len+ (int)sizeof(int8) <=buf->maxlen);
55-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int8));
56-
buf->len+=sizeof(int8);
54+
Assert(buf->len+ (int)sizeof(uint8) <=buf->maxlen);
55+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(uint8));
56+
buf->len+=sizeof(uint8);
5757
}
5858

5959
/*
60-
* Appendanint16 to a StringInfo buffer, which already has enough space
60+
* Appenda [u]int16 to a StringInfo buffer, which already has enough space
6161
* preallocated.
6262
*/
6363
staticinlinevoid
64-
pq_writeint16(StringInfoData*pg_restrictbuf,int16i)
64+
pq_writeint16(StringInfoData*pg_restrictbuf,uint16i)
6565
{
66-
int16ni=pg_hton16(i);
66+
uint16ni=pg_hton16(i);
6767

68-
Assert(buf->len+ (int)sizeof(int16) <=buf->maxlen);
69-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int16));
70-
buf->len+=sizeof(int16);
68+
Assert(buf->len+ (int)sizeof(uint16) <=buf->maxlen);
69+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(uint16));
70+
buf->len+=sizeof(uint16);
7171
}
7272

7373
/*
74-
* Appendanint32 to a StringInfo buffer, which already has enough space
74+
* Appenda [u]int32 to a StringInfo buffer, which already has enough space
7575
* preallocated.
7676
*/
7777
staticinlinevoid
78-
pq_writeint32(StringInfoData*pg_restrictbuf,int32i)
78+
pq_writeint32(StringInfoData*pg_restrictbuf,uint32i)
7979
{
80-
int32ni=pg_hton32(i);
80+
uint32ni=pg_hton32(i);
8181

82-
Assert(buf->len+ (int)sizeof(int32) <=buf->maxlen);
83-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int32));
84-
buf->len+=sizeof(int32);
82+
Assert(buf->len+ (int)sizeof(uint32) <=buf->maxlen);
83+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(uint32));
84+
buf->len+=sizeof(uint32);
8585
}
8686

8787
/*
88-
* Appendanint64 to a StringInfo buffer, which already has enough space
88+
* Appenda [u]int64 to a StringInfo buffer, which already has enough space
8989
* preallocated.
9090
*/
9191
staticinlinevoid
92-
pq_writeint64(StringInfoData*pg_restrictbuf,int64i)
92+
pq_writeint64(StringInfoData*pg_restrictbuf,uint64i)
9393
{
94-
int64ni=pg_hton64(i);
94+
uint64ni=pg_hton64(i);
9595

96-
Assert(buf->len+ (int)sizeof(int64) <=buf->maxlen);
97-
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(int64));
98-
buf->len+=sizeof(int64);
96+
Assert(buf->len+ (int)sizeof(uint64) <=buf->maxlen);
97+
memcpy((char*pg_restrict) (buf->data+buf->len),&ni,sizeof(uint64));
98+
buf->len+=sizeof(uint64);
9999
}
100100

101101
/*
@@ -127,41 +127,41 @@ pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
127127
pfree(p);
128128
}
129129

130-
/* append a binary int8 to a StringInfo buffer */
130+
/* append a binary[u]int8 to a StringInfo buffer */
131131
staticinlinevoid
132-
pq_sendint8(StringInfobuf,int8i)
132+
pq_sendint8(StringInfobuf,uint8i)
133133
{
134-
enlargeStringInfo(buf,sizeof(int8));
134+
enlargeStringInfo(buf,sizeof(uint8));
135135
pq_writeint8(buf,i);
136136
}
137137

138-
/* append a binary int16 to a StringInfo buffer */
138+
/* append a binary[u]int16 to a StringInfo buffer */
139139
staticinlinevoid
140-
pq_sendint16(StringInfobuf,int16i)
140+
pq_sendint16(StringInfobuf,uint16i)
141141
{
142-
enlargeStringInfo(buf,sizeof(int16));
142+
enlargeStringInfo(buf,sizeof(uint16));
143143
pq_writeint16(buf,i);
144144
}
145145

146-
/* append a binary int32 to a StringInfo buffer */
146+
/* append a binary[u]int32 to a StringInfo buffer */
147147
staticinlinevoid
148-
pq_sendint32(StringInfobuf,int32i)
148+
pq_sendint32(StringInfobuf,uint32i)
149149
{
150-
enlargeStringInfo(buf,sizeof(int32));
150+
enlargeStringInfo(buf,sizeof(uint32));
151151
pq_writeint32(buf,i);
152152
}
153153

154-
/* append a binary int64 to a StringInfo buffer */
154+
/* append a binary[u]int64 to a StringInfo buffer */
155155
staticinlinevoid
156-
pq_sendint64(StringInfobuf,int64i)
156+
pq_sendint64(StringInfobuf,uint64i)
157157
{
158-
enlargeStringInfo(buf,sizeof(int64));
158+
enlargeStringInfo(buf,sizeof(uint64));
159159
pq_writeint64(buf,i);
160160
}
161161

162162
/* append a binary byte to a StringInfo buffer */
163163
staticinlinevoid
164-
pq_sendbyte(StringInfobuf,int8byt)
164+
pq_sendbyte(StringInfobuf,uint8byt)
165165
{
166166
pq_sendint8(buf,byt);
167167
}
@@ -172,18 +172,18 @@ pq_sendbyte(StringInfo buf, int8 byt)
172172
* This function is deprecated; prefer use of the functions above.
173173
*/
174174
staticinlinevoid
175-
pq_sendint(StringInfobuf,inti,intb)
175+
pq_sendint(StringInfobuf,uint32i,intb)
176176
{
177177
switch (b)
178178
{
179179
case1:
180-
pq_sendint8(buf, (int8)i);
180+
pq_sendint8(buf, (uint8)i);
181181
break;
182182
case2:
183-
pq_sendint16(buf, (int16)i);
183+
pq_sendint16(buf, (uint16)i);
184184
break;
185185
case4:
186-
pq_sendint32(buf, (int32)i);
186+
pq_sendint32(buf, (uint32)i);
187187
break;
188188
default:
189189
elog(ERROR,"unsupported integer size %d",b);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp