From: <cha...@us...> - 2008-09-25 12:24:04
|
Revision: 539 http://sipp.svn.sourceforge.net/sipp/?rev=539&view=rev Author: charlespwright Date: 2008-09-25 11:32:11 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Fix: Do not try to allocate a zero length literal. Modified Paths: -------------- sipp/trunk/message.cpp Modified: sipp/trunk/message.cpp =================================================================== --- sipp/trunk/message.cpp 2008-09-25 02:35:53 UTC (rev 538) +++ sipp/trunk/message.cpp 2008-09-25 11:32:11 UTC (rev 539) @@ -134,25 +134,29 @@ *dest++ = *src++; } else { /* We have found a keyword, store the literal that we have been generating. */ - *dest = '\0'; literalLen = dest - literal; - literal = (char *)realloc(literal, literalLen); - if (!literal) { ERROR("Out of memory!"); } + if (literalLen) { + *dest = '\0'; + literal = (char *)realloc(literal, literalLen); + if (!literal) { ERROR("Out of memory!"); } - MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); - if (!newcomp) { ERROR("Out of memory!"); } + MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); + if (!newcomp) { ERROR("Out of memory!"); } - newcomp->type = E_Message_Literal; - newcomp->literal = literal; - newcomp->literalLen = literalLen; // length without the terminator - messageComponents.push_back(newcomp); + newcomp->type = E_Message_Literal; + newcomp->literal = literal; + newcomp->literalLen = literalLen; // length without the terminator + messageComponents.push_back(newcomp); + } else { + free(literal); + } dest = literal = (char *)malloc(strlen(src) + num_cr + 1); literalLen = 0; *dest = '\0'; /* Now lets determine which keyword we have. */ - newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); + MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); if (!newcomp) { ERROR("Out of memory!"); } char keyword [KEYWORD_SIZE+1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |