Skip to content

Commit d12d446

Browse files
author
James William Pye
committed
Don't forget ntohs.
1 parent 68d3533 commit d12d446

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

postgresql/protocol/optimized/element3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ parse_tuple_message(PyObject *self, PyObject *args)
5858
"invalid tuple message: %d bytes is too small", dlen);
5959
return(NULL);
6060
}
61-
natts = ntohs(*((uint16_t *) (data)));
61+
natts = local_ntohs(*((uint16_t *) (data)));
6262

6363
/*
6464
* FEARME: A bit much for saving a reallocation/copy?
@@ -91,7 +91,7 @@ parse_tuple_message(PyObject *self, PyObject *args)
9191
goto cleanup;
9292
}
9393

94-
attsize = ntohl(*((uint32_t *) (data + position)));
94+
attsize = local_ntohl(*((uint32_t *) (data + position)));
9595
position += 4;
9696
/*
9797
* NULL.

postgresql/protocol/optimized/module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
static PyObject *message_types = NULL;
2323
static long (*local_ntohl)(long) = NULL;
24+
static short (*local_ntohs)(short) = NULL;
2425

2526

2627
#include "typio.c"
@@ -74,11 +75,13 @@ PyInit_optimized(void)
7475
{
7576
/* little */
7677
local_ntohl = swap_long;
78+
local_ntohs = swap_short;
7779
}
7880
else
7981
{
8082
/* big */
8183
local_ntohl = return_long;
84+
local_ntohs = return_short;
8285
}
8386

8487
/*

postgresql/protocol/optimized/typio.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
c=P[4];P[4]=P[3];P[3]=c;\
3636
}while(0)
3737

38+
static short
39+
swap_short(short s)
40+
{
41+
swap2(((char *) &s));
42+
return(s);
43+
}
44+
45+
static short
46+
return_short(short s)
47+
{
48+
return(s);
49+
}
50+
3851
static long
3952
swap_long(long l)
4053
{

0 commit comments

Comments
 (0)