summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-07-12 14:46:45 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-07-14 06:48:48 +0200
commitd7f27477f448042ac212c29d5b209e37b83682ef (patch)
tree398a3d64eaed4503636b3608a7b9bf6dee0c63eb /src
parent5bad15d7ea1f50272da031beab9d613c1de2ec2d (diff)
downloadbison-d7f27477f448042ac212c29d5b209e37b83682ef.tar.gz
cex: more consistent memory allocation/copy
* src/counterexample.c, src/parse-simulation.c: It is more usual in Bison to use sizeof on expressions than on types, especially for allocation. Let the compiler do it's job instead of calling memcpy ourselves.
Diffstat (limited to 'src')
-rw-r--r--src/counterexample.c16
-rw-r--r--src/parse-simulation.c2
2 files changed, 9 insertions, 9 deletions
diff --git a/src/counterexample.c b/src/counterexample.c
index 4bc18428..478c9d53 100644
--- a/src/counterexample.c
+++ b/src/counterexample.c
@@ -84,7 +84,7 @@ static counterexample *
new_counterexample (derivation *d1, derivation *d2,
bool u, bool t)
{
- counterexample *res = xmalloc (sizeof (counterexample));
+ counterexample *res = xmalloc (sizeof *res);
res->d1 = d1;
res->d2 = d2;
res->unifying = u;
@@ -144,7 +144,7 @@ typedef struct si_bfs_node
static si_bfs_node *
si_bfs_new (state_item_number si, si_bfs_node *parent)
{
- si_bfs_node *res = xcalloc (1, sizeof (si_bfs_node));
+ si_bfs_node *res = xcalloc (1, sizeof *res);
res->si = si;
res->parent = parent;
res->reference_count = 1;
@@ -528,7 +528,7 @@ typedef struct
static search_state *
initial_search_state (state_item *conflict1, state_item *conflict2)
{
- search_state *res = xmalloc (sizeof (search_state));
+ search_state *res = xmalloc (sizeof *res);
res->states[0] = new_parse_state (conflict1);
res->states[1] = new_parse_state (conflict2);
parse_state_retain (res->states[0]);
@@ -540,7 +540,7 @@ initial_search_state (state_item *conflict1, state_item *conflict2)
static search_state *
new_search_state (parse_state *ps1, parse_state *ps2, int complexity)
{
- search_state *res = xmalloc (sizeof (search_state));
+ search_state *res = xmalloc (sizeof *res);
res->states[0] = ps1;
res->states[1] = ps2;
parse_state_retain (res->states[0]);
@@ -552,8 +552,8 @@ new_search_state (parse_state *ps1, parse_state *ps2, int complexity)
static search_state *
copy_search_state (search_state *parent)
{
- search_state *res = xmalloc (sizeof (search_state));
- memcpy (res, parent, sizeof (search_state));
+ search_state *res = xmalloc (sizeof *res);
+ *res = *parent;
parse_state_retain (res->states[0]);
parse_state_retain (res->states[1]);
return res;
@@ -709,7 +709,7 @@ ssb_append (search_state *ss)
parse_state_free_contents_early (ss->states[1]);
parse_state_retain (ss->states[0]);
parse_state_retain (ss->states[1]);
- search_state_bundle *ssb = xmalloc (sizeof (search_state_bundle));
+ search_state_bundle *ssb = xmalloc (sizeof *ssb);
ssb->complexity = ss->complexity;
gl_list_node_t n = gl_list_search (ssb_queue, ssb);
if (!n)
@@ -1295,7 +1295,7 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
{
item_number conf = *state_items[j].item;
if (item_number_is_symbol_number (conf)
- && bitset_test (reds->lookahead_tokens[i], conf))
+ && bitset_test (reds->lookahead_tokens[i], conf))
counterexample_report_shift_reduce (c1, j, conf, out, prefix);
}
for (int j = i+1; j < reds->num; ++j)
diff --git a/src/parse-simulation.c b/src/parse-simulation.c
index 940a99fe..bbf029b6 100644
--- a/src/parse-simulation.c
+++ b/src/parse-simulation.c
@@ -135,7 +135,7 @@ static parse_state *
copy_parse_state (bool prepend, parse_state *parent)
{
parse_state *res = xmalloc (sizeof *res);
- memcpy (res, parent, sizeof *res);
+ *res = *parent;
res->state_items.contents
= gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
res->derivs.contents = derivation_list_new ();