Research Article

An Efficient Platform for the Automatic Extraction of Patterns in Native Code

Algorithm 1

Example high-level C program.
char * str_slice(const char * str, int begin, int end)
/* Check str */
if (str == NULL)
return NULL;
/* Check ranges */
int s = strlen(str);
if ((!s) || (begin >= s) || (begin < s * −1) || (end >= s + 1)
|| (end < s * −1))
return NULL;
/* Normalice values */
size_t n_begin = begin >= 0 ? begin: s + begin;
size_t n_end = end >= 0 ? end: s + end;
/* Check begin >= end */
if (n_end <= n_begin)
return NULL;
/* Alloc mem */
size_t amount = n_end − n_begin;
char * new_str = malloc((amount + 1) * sizeof(char));
if (new_str == NULL)
return NULL;
/* Copy */
memcpy(new_str, str + n_begin, amount);
new_str[amount] = 0;
return new_str;