-const char pcrs_rcs[] = "$Id: pcrs.c,v 1.40 2012/03/09 17:55:50 fabiankeil Exp $";
+const char pcrs_rcs[] = "$Id: pcrs.c,v 1.45 2014/10/18 11:27:04 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/pcrs.c,v $
*/
const int ascii_value = xtoi(&replacement[i+2]);
- assert(ascii_value > 0);
+ assert(ascii_value >= 0);
assert(ascii_value < 256);
text[k++] = (char)ascii_value;
i += 4;
* 1 : job = the pcrs_job to be executed
* 2 : subject = the subject (== original) string
* 3 : subject_length = the subject's length
- * 4 : result = char** for returning the result
+ * 4 : result = char** for returning the result (NULL on error)
* 5 : result_length = size_t* for returning the result's length
*
* Returns : On success, the number of substitutions that were made.
char *result_offset;
offset = i = 0;
+ *result = NULL;
/*
* Sanity check & memory allocation
*/
if (job == NULL || job->pattern == NULL || job->substitute == NULL || NULL == subject)
{
- *result = NULL;
return(PCRS_ERR_BADJOB);
}
if (NULL == (matches = (pcrs_match *)malloc((size_t)max_matches * sizeof(pcrs_match))))
{
- *result = NULL;
return(PCRS_ERR_NOMEM);
}
memset(matches, '\0', (size_t)max_matches * sizeof(pcrs_match));
if (NULL == (dummy = (pcrs_match *)realloc(matches, (size_t)max_matches * sizeof(pcrs_match))))
{
free(matches);
- *result = NULL;
return(PCRS_ERR_NOMEM);
}
matches = dummy;
else
offset = offsets[1];
}
- /* Pass pcre error through if (bad) failiure */
+ /* Pass pcre error through if (bad) failure */
if (submatches < PCRE_ERROR_NOMATCH)
{
free(matches);
* Some characters that are unlikely to
* be part of pcrs replacement strings.
*/
- char delimiters[] = "><#+*~%^-:;!@";
- char *d = delimiters;
+ static const char delimiters[] = "><#+*~%^-:;!@";
+ const char *d = delimiters;
/* Take the first delimiter that isn't part of the string */
while (*d && NULL != strchr(string, *d))
{
/* No proper delimiter found */
*error = PCRS_ERR_CMDSYNTAX;
+ freez(pcrs_command_tmp);
return NULL;
}