diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index 4d4edd75ea4ae2e5ce8e7c11fb8641624e112b6c..5e5d05ba509d113c93cec02afb2018a8176ab048 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -3981,8 +3981,10 @@ transaction_request_cb (pjsip_rx_data *rdata)
     if (rdata->msg_info.msg->body) {
 
         char sdpbuffer[1000];
-        rdata->msg_info.msg->body->print_body (rdata->msg_info.msg->body, sdpbuffer, 1000);
-        std::string sdpoffer = std::string (sdpbuffer);
+        int len = rdata->msg_info.msg->body->print_body (rdata->msg_info.msg->body, sdpbuffer, 1000);
+        if (len == -1) // error
+                       len = 0;
+        std::string sdpoffer = std::string (sdpbuffer, len);
         size_t start = sdpoffer.find ("a=crypto:");
 
         // Found crypto header in SDP