Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1ed61b3

Browse files
committed
Fix unportable assumptions about alignment of local char[n] variables.
1 parent 39ceedf commit 1ed61b3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/interfaces/odbc/socket.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,29 @@ SOCK_put_string(SocketClass *self, char *string)
227227
int
228228
SOCK_get_int(SocketClass *self, short len)
229229
{
230-
char buf[4];
231-
232230
switch (len)
233231
{
234232
case 2:
235-
SOCK_get_n_char(self, buf, len);
233+
{
234+
unsigned short buf;
235+
236+
SOCK_get_n_char(self, (char *) &buf, len);
236237
if (self->reverse)
237-
return *((unsigned short *) buf);
238+
return buf;
238239
else
239-
return ntohs(*((unsigned short *) buf));
240+
return ntohs(buf);
241+
}
240242

241243
case 4:
242-
SOCK_get_n_char(self, buf, len);
244+
{
245+
unsigned int buf;
246+
247+
SOCK_get_n_char(self, (char *) &buf, len);
243248
if (self->reverse)
244-
return *((unsigned int *) buf);
249+
return buf;
245250
else
246-
return ntohl(*((unsigned int *) buf));
251+
return ntohl(buf);
252+
}
247253

248254
default:
249255
self->errornumber = SOCKET_GET_INT_WRONG_LENGTH;

0 commit comments

Comments
 (0)