* Returns 1 on success or 0 on error.
* The error code is set on reg->error.
*/
-int OSRegex_Compile(char *pattern, OSRegex *reg, int flags)
+int OSRegex_Compile(const char *pattern, OSRegex *reg, int flags)
{
- int i = 0;
- int count = 0;
+ size_t i = 0;
+ size_t count = 0;
int end_of_string = 0;
int parenthesis = 0;
- int prts_size = 0;
- int max_prts_size = 0;
+ unsigned prts_size = 0;
+ unsigned max_prts_size = 0;
char *pt;
char *new_str;
if(*pt == BACKSLASH)
{
pt++;
- if(!((*pt == 'w') ||
- (*pt == 'W') ||
- (*pt == 's') ||
- (*pt == 'S') ||
- (*pt == 'd') ||
- (*pt == 'D') ||
- (*pt == '.') ||
- (*pt == '(') ||
- (*pt == ')') ||
- (*pt == 'p') ||
- (*pt == 't') ||
- (*pt == '$') ||
- (*pt == '|') ||
- (*pt == '<') ||
- (*pt == '\\')))
- {
- reg->error = OS_REGEX_BADREGEX;
- goto compile_error;
- }
-
/* Giving the new values for each regex */
switch(*pt)
{
case '$': *pt = 13;break;
case '|': *pt = 14;break;
case '<': *pt = 15;break;
+ default:
+ reg->error = OS_REGEX_BADREGEX;
+ goto compile_error;
}
pt++;
*/
if(!(flags & OS_CASE_SENSITIVE))
{
- *pt = charmap[(uchar)*pt];
+ *pt = (char) charmap[(uchar)*pt];
}
if(*pt == OR)
/* Allocating the memory for the sub patterns */
count++;
- reg->patterns = calloc(count +1, sizeof(char *));
- reg->flags = calloc(count +1, sizeof(int));
+ reg->patterns = (char **) calloc(count +1, sizeof(char *));
+ reg->flags = (int *) calloc(count +1, sizeof(int));
+
+ /* Memory allocation error check */
+ if(!reg->patterns || !reg->flags)
+ {
+ reg->error = OS_REGEX_OUTOFMEMORY;
+ goto compile_error;
+ }
/* For the substrings */
if((prts_size > 0) && (flags & OS_RETURN_SUBSTRING))
{
- reg->prts_closure = calloc(count +1, sizeof(char **));
- reg->prts_str = calloc(count +1, sizeof(char **));
+ reg->prts_closure = (const char ***) calloc(count +1, sizeof(const char **));
+ reg->prts_str = (const char ***) calloc(count +1, sizeof(const char **));
if(!reg->prts_closure || !reg->prts_str)
{
reg->error = OS_REGEX_OUTOFMEMORY;
}
- /* Memory allocation error check */
- if(!reg->patterns || !reg->flags)
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
-
/* Initializing each sub pattern */
for(i = 0; i<=count; i++)
{
/* The parenthesis closure if set */
if(reg->prts_closure)
{
- int tmp_int = 0;
+ unsigned tmp_int = 0;
char *tmp_str;
}
/* Allocating the memory */
- reg->prts_closure[i] = calloc(prts_size + 1, sizeof(char *));
- reg->prts_str[i] = calloc(prts_size + 1, sizeof(char *));
+ reg->prts_closure[i] = (const char **) calloc(prts_size + 1, sizeof(const char *));
+ reg->prts_str[i] = (const char **) calloc(prts_size + 1, sizeof(const char *));
if((reg->prts_closure[i] == NULL)||(reg->prts_str[i] == NULL))
{
reg->error = OS_REGEX_OUTOFMEMORY;
}while(!end_of_string);
/* Allocating sub string for the maximum number of parenthesis */
- reg->sub_strings = calloc(max_prts_size + 1, sizeof(char *));
+ reg->sub_strings = (char **) calloc(max_prts_size + 1, sizeof(char *));
if(reg->sub_strings == NULL)
{
reg->error = OS_REGEX_OUTOFMEMORY;