mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
(WRITE_SIGNED_TYPE): Avoid alignment errors by using memcpy() instead
of trying to assign to (_TYPE*)(BUFFER+1). (WRITE_UNSIGNED_TYPE): Likewise. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1595 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
606e7dbd04
commit
feccda75ec
1 changed files with 20 additions and 15 deletions
|
@ -106,20 +106,23 @@ static int debug_binary_coder = 0;
|
|||
|
||||
[stream writeByte: *type];
|
||||
|
||||
#define WRITE_SIGNED_TYPE(_PTR, _TYPE, _CONV_FUNC) \
|
||||
{ \
|
||||
char buffer[1+sizeof(_TYPE)]; \
|
||||
buffer[0] = sizeof (_TYPE); \
|
||||
if (*(_TYPE*)_PTR < 0) \
|
||||
{ \
|
||||
buffer[0] |= 0x80; \
|
||||
*(_TYPE*)(buffer+1) = _CONV_FUNC (- *(_TYPE*)_PTR); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
*(_TYPE*)(buffer+1) = _CONV_FUNC (*(_TYPE*)_PTR); \
|
||||
} \
|
||||
[stream writeBytes: buffer length: 1+sizeof(_TYPE)]; \
|
||||
#define WRITE_SIGNED_TYPE(_PTR, _TYPE, _CONV_FUNC) \
|
||||
{ \
|
||||
_TYPE tmp; \
|
||||
char buffer[1+sizeof(_TYPE)]; \
|
||||
buffer[0] = sizeof (_TYPE); \
|
||||
if (*(_TYPE*)_PTR < 0) \
|
||||
{ \
|
||||
buffer[0] |= 0x80; \
|
||||
tmp = _CONV_FUNC (- *(_TYPE*)_PTR); \
|
||||
memcpy (buffer+1, &tmp, sizeof(_TYPE)); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
tmp = _CONV_FUNC (*(_TYPE*)_PTR); \
|
||||
memcpy (buffer+1, &tmp, sizeof(_TYPE)); \
|
||||
} \
|
||||
[stream writeBytes: buffer length: 1+sizeof(_TYPE)]; \
|
||||
}
|
||||
|
||||
#define READ_SIGNED_TYPE(_PTR, _TYPE, _CONV_FUNC) \
|
||||
|
@ -145,9 +148,11 @@ static int debug_binary_coder = 0;
|
|||
|
||||
#define WRITE_UNSIGNED_TYPE(_PTR, _TYPE, _CONV_FUNC) \
|
||||
{ \
|
||||
_TYPE tmp; \
|
||||
char buffer[1+sizeof(_TYPE)]; \
|
||||
buffer[0] = sizeof (_TYPE); \
|
||||
*(_TYPE*)(buffer+1) = _CONV_FUNC (*(_TYPE*)_PTR); \
|
||||
tmp = _CONV_FUNC (*(_TYPE*)_PTR); \
|
||||
memcpy (buffer+1, &tmp, sizeof(_TYPE)); \
|
||||
[stream writeBytes: buffer length: (1+sizeof(_TYPE))]; \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue