+From cfeb1a1ee25865b2d8ba7b8a5ea4ad815077b353 Mon Sep 17 00:00:00 2001
+From: Arsen Chaloyan <achaloyan@gmail.com>
+Date: Wed, 23 Apr 2014 13:33:03 -0700
+Subject: [PATCH] Comply with the aggressive-loop-optimization introduced in
+ gcc 4.8.
+
+The problem is in gcc loop optimizers which detect a loop operating with out of bounds memory and then optimize it with something undefined since, according to the C standard, out of bounds behavior is undefined. The problem could have been addressed by using the new option -fno-aggressive-loop-optimization as well.
+---
+ libsofia-sip-ua/msg/msg_parser.c | 16 +++++++++-------
+ 1 file changed, 9 insertions(+), 7 deletions(-)
+
+diff --git a/libsofia-sip-ua/msg/msg_parser.c b/libsofia-sip-ua/msg/msg_parser.c
+index 6f796eb..76185f3 100644
+--- a/libsofia-sip-ua/msg/msg_parser.c
++++ b/libsofia-sip-ua/msg/msg_parser.c
+@@ -2530,8 +2530,6 @@ int msg_header_prepend(msg_t *msg,
+ msg_header_t **
+ msg_hclass_offset(msg_mclass_t const *mc, msg_pub_t const *mo, msg_hclass_t *hc)
+ {
+- int i;
+-
+ assert(mc && hc);
+
+ if (mc == NULL || hc == NULL)
+@@ -2543,12 +2541,16 @@ msg_hclass_offset(msg_mclass_t const *mc, msg_pub_t const *mo, msg_hclass_t *hc)
+ if (mc->mc_hash[j].hr_class == hc) {
+ return (msg_header_t **)((char *)mo + mc->mc_hash[j].hr_offset);
+ }
+- }
+- else
++ } else {
+ /* Header has no name. */
+- for (i = 0; i <= 6; i++)
+- if (hc->hc_hash == mc->mc_request[i].hr_class->hc_hash)
+- return (msg_header_t **)((char *)mo + mc->mc_request[i].hr_offset);
++ if (hc->hc_hash == mc->mc_request[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_request[0].hr_offset);
++ if (hc->hc_hash == mc->mc_status[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_status[0].hr_offset);
++ if (hc->hc_hash == mc->mc_separator[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_separator[0].hr_offset);
++ if (hc->hc_hash == mc->mc_payload[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_payload[0].hr_offset);
++ if (hc->hc_hash == mc->mc_unknown[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_unknown[0].hr_offset);
++ if (hc->hc_hash == mc->mc_error[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_error[0].hr_offset);
++ if (hc->hc_hash == mc->mc_multipart[0].hr_class->hc_hash) return (msg_header_t **)((char *)mo + mc->mc_multipart[0].hr_offset);
++ }
+
+ return NULL;
+ }
+diff --git a/libsofia-sip-ua/sip/sofia-sip/sip.h b/libsofia-sip-ua/sip/sofia-sip/sip.h
+index 793af0e..e8f3a4b 100644
+--- a/libsofia-sip-ua/sip/sofia-sip/sip.h
++++ b/libsofia-sip-ua/sip/sofia-sip/sip.h
+@@ -26,6 +26,8 @@
+ /** Defined when <sofia-sip/sip.h> has been included. */
+ #define SIP_H
+
++#define SOFIA_SIP_GCC_4_8_PATCH_APLLIED
++
+ /**@file sofia-sip/sip.h
+ *
+ * SIP objects.