aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2010-02-03 06:49:27 +0000
committerYang Tse <yangsita@gmail.com>2010-02-03 06:49:27 +0000
commit381a4d6efec42db823cbd5946514c275bca7d2d1 (patch)
tree061eb754d2156ea5b143b79eb9e3f843684961bd /tests
parentf6d288a39740136c59ee14937f994ca5e1555016 (diff)
Fix portability issue related with unaligned memory access
Diffstat (limited to 'tests')
-rw-r--r--tests/libtest/lib571.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c
index f69151467..a1cd032ab 100644
--- a/tests/libtest/lib571.c
+++ b/tests/libtest/lib571.c
@@ -33,6 +33,11 @@
#include "memdebug.h"
+#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
+
+#define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
+ ((int)((unsigned char)((p)[3]))))
+
#define RTP_DATA_SIZE 12
static const char *RTP_DATA = "$_1234\n\0asdf";
@@ -40,16 +45,18 @@ static int rtp_packet_count = 0;
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
char *data = (char *)ptr;
- int channel = (int)data[1];
- int message_size = (int)(size * nmemb - 4);
- unsigned short coded_size = ntohs(*((unsigned short*)(&data[2])));
+ int channel = RTP_PKT_CHANNEL(data);
+ int message_size = (int)(size * nmemb) - 4;
+ int coded_size = RTP_PKT_LENGTH(data);
+ size_t failure = (size * nmemb) ? 0 : 1;
int i;
(void)stream;
printf("RTP: message size %d, channel %d\n", message_size, channel);
- if((unsigned short) message_size != coded_size) {
- printf("RTP embedded size (%hu) does not match the write size (%d).\n",
- coded_size, message_size);
+ if(message_size != coded_size) {
+ printf("RTP embedded size (%d) does not match the write size (%d).\n",
+ coded_size, message_size);
+ return failure;
}
data += 4;
@@ -57,11 +64,13 @@ static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
if(message_size - i > RTP_DATA_SIZE) {
if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
+ return failure;
}
} else {
if (memcmp(RTP_DATA, data + i, message_size - i) != 0) {
printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
message_size - i, data + i);
+ return failure;
}
}
}