Permalink
Browse files

Add an assertion if particular indices in an array/struct are duplica…

…tes.

Fix struct/array index lookup if the previous entry used a designated
initializer, but this particular entry didn't. In that case, our index
is the previous member's index + 1, but we used to use the counter as
index, which is wrong.

Also fix the unit test, which contained code triggering both problems,
which ended up going in an infinite loop.
  • Loading branch information...
1 parent eb79e74 commit 47826cc230b64d99fb357956b242c5908510be1e @rbultje committed Dec 19, 2012
Showing with 22 additions and 2 deletions.
  1. +20 −2 convert.c
  2. +2 −0 unit2.c
View
22 convert.c
@@ -1233,6 +1233,17 @@ static char *find_variable_name(CursorRecursion *rec)
abort();
}
+static int index_is_unique(StructArrayList *l, int idx) {
+ int n;
+
+ for (n = 0; n < l->n_entries; n++) {
+ if (l->entries[n].index == idx)
+ return 0;
+ }
+
+ return 1;
+}
+
static enum CXChildVisitResult callback(CXCursor cursor, CXCursor parent,
CXClientData client_data)
{
@@ -1492,7 +1503,9 @@ static enum CXChildVisitResult callback(CXCursor cursor, CXCursor parent,
sai->value_offset.end = e;
sai->expression_offset.start = s;
sai->expression_offset.end = e;
- sai->index = rec.parent->child_cntr - 1;
+ sai->index = parent->n_entries > 0 ?
+ parent->entries[parent->n_entries - 1].index + 1 :
+ rec.parent->child_cntr - 1;
parent_idx = parent - struct_array_lists;
}
}
@@ -1580,6 +1593,8 @@ static enum CXChildVisitResult callback(CXCursor cursor, CXCursor parent,
sai->value_offset.end = get_token_offset(tokens[n_tokens - 2]);
rec.data.sal_idx = rec.parent->data.sal_idx;
clang_visitChildren(cursor, callback, &rec);
+ assert(index_is_unique(&struct_array_lists[rec.parent->data.sal_idx],
+ sai->index));
struct_array_lists[rec.parent->data.sal_idx].n_entries++;
clang_disposeString(spelling);
clang_disposeString(spelling2);
@@ -1681,7 +1696,10 @@ static enum CXChildVisitResult callback(CXCursor cursor, CXCursor parent,
sai->value_offset.end = s;
sai->expression_offset.start = s;
sai->expression_offset.end = s;
- sai->index = rec.parent->child_cntr - 1;
+ sai->index = parent->n_entries > 0 ?
+ parent->entries[parent->n_entries - 1].index + 1 :
+ rec.parent->child_cntr - 1;
+ assert(index_is_unique(parent, sai->index));
parent->n_entries++;
}
}
View
2 unit2.c
@@ -9,8 +9,10 @@ typedef struct PixFmtInfo {
enum PixelFormat {
PIX_FMT_YUV420P,
PIX_FMT_YUYV422,
+ PIX_FMT_DUMMY3,
PIX_FMT_YUVJ420P,
PIX_FMT_RGB24,
+ PIX_FMT_RGB555,
PIX_FMT_RGBA,
PIX_FMT_DUMMY,
PIX_FMT_DUMMY2,

0 comments on commit 47826cc

Please sign in to comment.