/* * parse a complex expression list like a, b, c EXCEPT d, e * return 0 on success, -1 on error * parsed expressions are returned in **e, and exceptions are returned in **e_exceptions */ static int parse_expression(char *str, expression **e, expression **e_exceptions) { char *except, str2[LINE_LENGTH]; int i=0, l; if (!str || !e || !e_exceptions) return -1; except = strstr(str, " EXCEPT "); if (except) { /* exception found */ l = except-str; if (l >= LINE_LENGTH) { /* error */ LOG(L_ERR, "ERROR: parse_expression(): too long config line, increase LINE_LENGTH\n"); goto error; } strncpy(str2, str, l); str2[l] = '\0'; /* except+8 points to the exception */ if (parse_expression_list(except+8, e_exceptions)) { /* error */ goto error; } } else { /* no exception */ l = strlen(str); if (l >= LINE_LENGTH) { /* error */ LOG(L_ERR, "ERROR: parse_expression(): too long config line, increase LINE_LENGTH\n"); goto error; } strncpy(str2, str, l); str2[l] = '\0'; *e_exceptions = NULL; } while ((str2[i] == ' ') || (str2[i] == '\t')) i++; if (strncmp("ALL", str2+i, 3) == 0) { *e = NULL; } else { if (parse_expression_list(str2+i, e)) { /* error */ if (*e_exceptions) free_expression(*e_exceptions); goto error; } } return 0; error: *e = *e_exceptions = NULL; return -1; }
int main () { char A [2 + 2 + 4 +1]; A[2 + 2 + 4] = 0; parse_expression_list (A); return 0; }
int main () { char A [LINE_LENGTH+1]; A[LINE_LENGTH] = EOS; parse_expression_list (A); return 0; }
/* * parse a complex expression list like a, b, c EXCEPT d, e * return 0 on success, -1 on error * parsed expressions are returned in **e, and exceptions are returned in **e_exceptions */ static int parse_expression(char *sv, expression **e, expression **e_exceptions) { char *except, str2[LINE_LENGTH+1]; int i,j; if (!sv || !e || !e_exceptions) return -1; if(strlen(sv)>=LINE_LENGTH) { LM_ERR("expression string is too long (%s)\n", sv); return -1; } except = strstr(sv, " EXCEPT "); if (except) { /* exception found */ strncpy(str2, sv, except-sv); str2[except-sv] = '\0'; /* except+8 points to the exception */ if (parse_expression_list(except+8, e_exceptions)) { /* error */ *e = *e_exceptions = NULL; return -1; } } else { /* no exception */ strcpy(str2, sv); *e_exceptions = NULL; } for( i=0; isspace((int)str2[i]) ; i++); for( j=strlen(str2)-1 ; isspace((int)str2[j]) ; str2[j--]=0); if (strcmp("ALL", str2+i) == 0) { *e = NULL; } else { if (parse_expression_list(str2+i, e)) { /* error */ if (*e_exceptions) free_expression(*e_exceptions); *e = *e_exceptions = NULL; return -1; } } return 0; }
int main () { char A [LINE_LENGTH+1]; for (int i = 0; i < LINE_LENGTH; i++) { A[i] = __VERIFIER_nondet_char(); } A[LINE_LENGTH] = EOS; parse_expression_list (A); return 0; }
int parse_expression (char *str) { char *except; char str2 [LINE_LENGTH+1]; except = strstr(str, NEEDLE); if (except) { strncpy(str2, str, except-str); str2[except-str] = EOS; if (parse_expression_list(except+NEEDLE_SZ)) { /* error */ return -1; } } return 0; }