Updated function to save to parameter instead of leaving memory issues as noted above
void findValue(const char * originalStr,char * leftBound, char * rightBound,int * offset, char * savedParamName)
{
char search_str[50];
char * start_position;
char * end_position;
char * returnStr;
int offset1,offset2;
// ADDED
if(originalStr==NULL)
{
lr_save_string('''',savedParamName);
// return NULL;
return;
}
sprintf(search_str,leftBound);
start_position = (char *)strstr(originalStr,search_str);
if(start_position!=NULL)
{
offset1 = (int)(start_position - originalStr);
*offset = offset1+strlen(search_str);
start_position+=strlen(search_str);
sprintf(search_str,rightBound);
end_position = (char *)strstr(start_position,search_str);
if(end_position!=NULL)
{
offset2 = (int)(end_position - start_position);
*offset += offset2;
if((returnStr = (char *)malloc((offset2+1)*sizeof(char)))==NULL)
{
lr_output_message(''calloc error - not enough memory to allocate'');
lr_exit(LR_EXIT_VUSER,LR_FAIL);
}
//lr_output_message(''start_pos = %d - offset 2 = %d'',start_position,offset2);
strncpy(returnStr,start_position,offset2);
//lr_output_message(''returnStr = %s'',returnStr);
returnStr[offset2]=' '; // make sure null char is set at the end
}
else
{
lr_save_string('''',savedParamName);
// return NULL;
return;
}
}
else
{
lr_save_string('''',savedParamName);
// return NULL;
return;
}
lr_save_string(returnStr,savedParamName);
//return returnStr;
free(returnStr);
}