Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/eos/core/src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EosResult eos_graph_add_node(EosGraph *g, const char *name, EosNodeType type,
int id = g->node_count;
EosNode *n = &g->nodes[id];
strncpy(n->name, name, EOS_MAX_NAME - 1);
n->name[EOS_MAX_NAME-1] = '\0';
n->type = type;
n->build_type = build_type;
n->status = EOS_NODE_PENDING;
Expand Down
40 changes: 40 additions & 0 deletions core/eos/tests/test_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,46 @@ static void test_graph_add_nodes(void) {

ASSERT(g.node_count == 3, "graph has 3 nodes");
}
static void test_graph_max_length_node_name(void) {
printf("test_graph_max_length_node_name:\n");

EosGraph g;
eos_graph_init(&g);

char name[EOS_MAX_NAME];

/* Create a name that fills the buffer except for the null terminator. */
memset(name, 'A', EOS_MAX_NAME - 1);
name[EOS_MAX_NAME - 1] = '\0';

/*
* Fill the destination with non-zero data so the test can detect
* a missing null terminator even though eos_graph_init() zeroes
* the graph initially.
*/
memset(g.nodes[0].name, 'X', EOS_MAX_NAME);

int id;
EosResult r = eos_graph_add_node(
&g,
name,
EOS_NODE_PACKAGE,
EOS_BUILD_CMAKE,
&id
);

ASSERT(r == EOS_OK, "maximum-length node name can be added");

ASSERT(
g.nodes[id].name[EOS_MAX_NAME - 1] == '\0',
"node name is null terminated"
);

ASSERT(
eos_graph_find_node(&g, name) == id,
"maximum-length node name can be found"
);
}
static void test_graph_find_node(void) {
printf("test_graph_find_node:\n");
EosGraph g;
Expand Down Expand Up @@ -168,6 +207,7 @@ int main(void) {
test_graph_init();
test_graph_add_nodes();
test_graph_find_node();
test_graph_max_length_node_name();
test_topological_sort_linear();
test_topological_sort_diamond();
test_cycle_detection();
Expand Down