packet.c | packet.c | |||
---|---|---|---|---|
skipping to change at line 29 | skipping to change at line 29 | |||
ENetPacket * | ENetPacket * | |||
enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags ) | enet_packet_create (const void * data, size_t dataLength, enet_uint32 flags ) | |||
{ | { | |||
ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket)); | ENetPacket * packet = (ENetPacket *) enet_malloc (sizeof (ENetPacket)); | |||
if (packet == NULL) | if (packet == NULL) | |||
return NULL; | return NULL; | |||
if (flags & ENET_PACKET_FLAG_NO_ALLOCATE) | if (flags & ENET_PACKET_FLAG_NO_ALLOCATE) | |||
packet -> data = (enet_uint8 *) data; | packet -> data = (enet_uint8 *) data; | |||
else | else | |||
if (dataLength <= 0) | ||||
packet -> data = NULL; | ||||
else | ||||
{ | { | |||
packet -> data = (enet_uint8 *) enet_malloc (dataLength); | packet -> data = (enet_uint8 *) enet_malloc (dataLength); | |||
if (packet -> data == NULL) | if (packet -> data == NULL) | |||
{ | { | |||
enet_free (packet); | enet_free (packet); | |||
return NULL; | return NULL; | |||
} | } | |||
if (data != NULL) | if (data != NULL) | |||
memcpy (packet -> data, data, dataLength); | memcpy (packet -> data, data, dataLength); | |||
skipping to change at line 57 | skipping to change at line 60 | |||
} | } | |||
/** Destroys the packet and deallocates its data. | /** Destroys the packet and deallocates its data. | |||
@param packet packet to be destroyed | @param packet packet to be destroyed | |||
*/ | */ | |||
void | void | |||
enet_packet_destroy (ENetPacket * packet) | enet_packet_destroy (ENetPacket * packet) | |||
{ | { | |||
if (packet -> freeCallback != NULL) | if (packet -> freeCallback != NULL) | |||
(* packet -> freeCallback) (packet); | (* packet -> freeCallback) (packet); | |||
if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE)) | if (! (packet -> flags & ENET_PACKET_FLAG_NO_ALLOCATE) && | |||
packet -> data != NULL) | ||||
enet_free (packet -> data); | enet_free (packet -> data); | |||
enet_free (packet); | enet_free (packet); | |||
} | } | |||
/** Attempts to resize the data in the packet to length specified in the | /** Attempts to resize the data in the packet to length specified in the | |||
dataLength parameter | dataLength parameter | |||
@param packet packet to resize | @param packet packet to resize | |||
@param dataLength new size for the packet data | @param dataLength new size for the packet data | |||
@returns 0 on success, < 0 on failure | @returns 0 on success, < 0 on failure | |||
*/ | */ | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 5 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |