Fix readshort/long signyness

This commit is contained in:
Erik Ekman 2006-08-23 16:03:24 +00:00
parent 2a0f3e42d9
commit 77ec951b01

17
read.c
View file

@ -57,11 +57,10 @@ readname(char *packet, char **src, char *dst, size_t length)
int int
readshort(char *packet, char **src, short *dst) readshort(char *packet, char **src, short *dst)
{ {
char *p; unsigned char *p;
p = *src; p = *src;
*dst = ((short)p[0] << 8) *dst = (p[0] << 8) | p[1];
| ((short)p[1]);
(*src) += sizeof(short); (*src) += sizeof(short);
return sizeof(short); return sizeof(short);
@ -70,7 +69,7 @@ readshort(char *packet, char **src, short *dst)
int int
readlong(char *packet, char **src, long *dst) readlong(char *packet, char **src, long *dst)
{ {
char *p; unsigned char *p;
p = *src; p = *src;
@ -86,6 +85,9 @@ readlong(char *packet, char **src, long *dst)
int int
readdata(char *packet, char **src, char *dst, size_t len) readdata(char *packet, char **src, char *dst, size_t len)
{ {
if (len < 0)
return len;
memcpy(dst, *src, len); memcpy(dst, *src, len);
(*src) += len; (*src) += len;
@ -105,7 +107,7 @@ putbyte(char **dst, char value)
int int
putshort(char **dst, short value) putshort(char **dst, short value)
{ {
char *p; unsigned char *p;
p = *dst; p = *dst;
@ -119,7 +121,7 @@ putshort(char **dst, short value)
int int
putlong(char **dst, long value) putlong(char **dst, long value)
{ {
char *p; unsigned char *p;
p = *dst; p = *dst;
@ -135,6 +137,9 @@ putlong(char **dst, long value)
int int
putdata(char **dst, char *data, size_t len) putdata(char **dst, char *data, size_t len)
{ {
if (len < 0)
return len;
memcpy(*dst, data, len); memcpy(*dst, data, len);
(*dst) += len; (*dst) += len;