[asterisk-commits] trunk r26846 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu May 11 03:22:18 MST 2006


Author: rizzo
Date: Thu May 11 05:22:18 2006
New Revision: 26846

URL: http://svn.digium.com/view/asterisk?rev=26846&view=rev
Log:
remove duplicated code in add_header


Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=26846&r1=26845&r2=26846&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu May 11 05:22:18 2006
@@ -4111,6 +4111,8 @@
 /*! \brief Add header to SIP message */
 static int add_header(struct sip_request *req, const char *var, const char *value)
 {
+	int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */
+
 	if (req->headers == SIP_MAX_HEADERS) {
 		ast_log(LOG_WARNING, "Out of SIP header space\n");
 		return -1;
@@ -4121,7 +4123,7 @@
 		return -1;
 	}
 
-	if (req->len >= sizeof(req->data) - 4) {
+	if (maxlen <= 0) {
 		ast_log(LOG_WARNING, "Out of space, can't add anymore (%s:%s)\n", var, value);
 		return -1;
 	}
@@ -4131,7 +4133,7 @@
 	if (compactheaders)
 		var = find_alias(var, var);
 
-	snprintf(req->header[req->headers], sizeof(req->data) - req->len - 4, "%s: %s\r\n", var, value);
+	snprintf(req->header[req->headers], maxlen, "%s: %s\r\n", var, value);
 	req->len += strlen(req->header[req->headers]);
 	req->headers++;
 



More information about the asterisk-commits mailing list