Commit 90abca99 authored by Dafydd Harries's avatar Dafydd Harries

modify stun_message_unpack to avoid signed/unsigned comparison and increase readability

darcs-hash:20070110164125-c9803-f2c96f8e69b8c1273aae2f49a72768bd7f1bf763.gz
parent 73c24910
...@@ -134,10 +134,10 @@ stun_message_free (StunMessage *msg) ...@@ -134,10 +134,10 @@ stun_message_free (StunMessage *msg)
StunMessage * StunMessage *
stun_message_unpack (guint length, gchar *s) stun_message_unpack (guint length, gchar *s)
{ {
gchar *t;
guint attr_length; guint attr_length;
guint n_attributes = 0; guint n_attributes = 0;
guint i; guint i;
guint offset;
StunAttribute *attr; StunAttribute *attr;
StunMessage *msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST); StunMessage *msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
...@@ -152,8 +152,8 @@ stun_message_unpack (guint length, gchar *s) ...@@ -152,8 +152,8 @@ stun_message_unpack (guint length, gchar *s)
/* count the number of attributes */ /* count the number of attributes */
for (t = s + 20; t - s < length; t += attr_length + 4) { for (offset = 20; offset < length; offset += attr_length + 4) {
attr_length = ntohs (*(guint16 *)(t + 2)); attr_length = ntohs (*(guint16 *)(s + offset + 2));
n_attributes++; n_attributes++;
} }
...@@ -164,9 +164,9 @@ stun_message_unpack (guint length, gchar *s) ...@@ -164,9 +164,9 @@ stun_message_unpack (guint length, gchar *s)
/* unpack attributes */ /* unpack attributes */
for (i = 0, t = s + 20; i < n_attributes; i++, t += attr_length + 4) { for (i = 0, offset = 20; i < n_attributes; i++, offset += attr_length + 4) {
attr_length = ntohs (*(guint16 *)(t + 2)); attr_length = ntohs (*(guint16 *)(s + offset + 2));
attr = msg->attributes[i] = stun_attribute_unpack (attr_length, t); attr = msg->attributes[i] = stun_attribute_unpack (attr_length, s + offset);
} }
return msg; return msg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment