inp_search_opening_paren(), rewrite

This commit is contained in:
rlar 2013-10-03 11:54:58 +02:00
parent 87f53913bd
commit 3e3cbab668
1 changed files with 10 additions and 4 deletions

View File

@ -1810,17 +1810,19 @@ inp_search_closing_paren(char *s)
static char * static char *
inp_search_opening_paren(char *s, char *start) inp_search_opening_paren(char *s, char *start)
{ {
int count = 1; int count = 0;
// assert(*s == ')') // assert(*s == ')')
while ((count != 0) && (s != start)) { while (s >= start) {
s--;
if (*s == '(') if (*s == '(')
count--; count--;
if (*s == ')') if (*s == ')')
count++; count++;
if (count == 0)
return s;
s--;
} }
return s; return NULL;
} }
@ -1876,6 +1878,10 @@ inp_fix_ternary_operator_str(char *line, bool all)
/* test for (conditional)?... */ /* test for (conditional)?... */
if (str_ptr2[-1] == ')') { if (str_ptr2[-1] == ')') {
str_ptr = inp_search_opening_paren(str_ptr2 - 1, line); str_ptr = inp_search_opening_paren(str_ptr2 - 1, line);
if (!str_ptr) {
fprintf(stderr, "ERROR: problem parsing 'if' of ternary string %s!\n", line);
controlled_exit(EXIT_FAILURE);
}
} }
/* test for (conditional?... */ /* test for (conditional?... */
else { else {