aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/parse-error.c2
-rw-r--r--src/mds-kbdc/tree.c46
2 files changed, 21 insertions, 27 deletions
diff --git a/src/mds-kbdc/parse-error.c b/src/mds-kbdc/parse-error.c
index dfaf116..d08ac38 100644
--- a/src/mds-kbdc/parse-error.c
+++ b/src/mds-kbdc/parse-error.c
@@ -71,7 +71,7 @@ void mds_kbdc_parse_error_print(const mds_kbdc_parse_error_t* restrict this, FIL
}
*dptr = '\0';
- /* Convert bytes count to character count for the code position */
+ /* Convert bytes count to character count for the code position. */
for (i = 0, n = this->start; i < n; i++)
if ((code[i] & 0xC0) != 0x80)
start++;
diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c
index a107408..eef2d7f 100644
--- a/src/mds-kbdc/tree.c
+++ b/src/mds-kbdc/tree.c
@@ -17,12 +17,22 @@
*/
#include "tree.h"
+#include <libmdsserver/macros.h>
+#undef xfree
+
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+/* Helper `typedef`:s */
+typedef struct mds_kbdc_tree_nesting mds_kbdc_tree_nesting_t;
+typedef struct mds_kbdc_tree_callable mds_kbdc_tree_callable_t;
+typedef struct mds_kbdc_tree_information_data mds_kbdc_tree_information_data_t;
+
+
+
/**
* Tree type constant shortener
*/
@@ -233,8 +243,8 @@ void mds_kbdc_tree_free(mds_kbdc_tree_t* restrict this)
*
* @param member:identifer The member in the tree to duplicate
*/
-#define T(member) \
- if (t->member && (n->member = mds_kbdc_tree_dup(t->member), n->member == NULL)) goto fail
+#define T(member) \
+ fail_if (t->member && (n->member = mds_kbdc_tree_dup(t->member), n->member == NULL))
/**
@@ -242,8 +252,8 @@ void mds_kbdc_tree_free(mds_kbdc_tree_t* restrict this)
*
* @param member:identifer The member in the tree to duplicate
*/
-#define S(member) \
- if (t->member && (n->member = strdup(t->member), n->member == NULL)) goto fail
+#define S(member) \
+ fail_if (t->member && (n->member = strdup(t->member), n->member == NULL))
/**
@@ -264,25 +274,18 @@ void mds_kbdc_tree_free(mds_kbdc_tree_t* restrict this)
*/
mds_kbdc_tree_t* mds_kbdc_tree_dup(mds_kbdc_tree_t* restrict this)
{
- typedef struct mds_kbdc_tree_nesting mds_kbdc_tree_nesting_t;
- typedef struct mds_kbdc_tree_callable mds_kbdc_tree_callable_t;
- typedef struct mds_kbdc_tree_information_data mds_kbdc_tree_information_data_t;
- mds_kbdc_tree_t* node = calloc(1, sizeof(mds_kbdc_tree_t));
+ mds_kbdc_tree_t* node = NULL;
int saved_errno;
- if (node == NULL)
- return NULL;
+ fail_if ((this == NULL) || xcalloc(node, 1, sizeof(mds_kbdc_tree_t)));
node->type = this->type;
node->loc_line = this->loc_line;
node->loc_start = this->loc_start;
node->loc_end = this->loc_end;
node->processed = this->processed;
- if (this->next)
- {
- node->next = mds_kbdc_tree_dup(this->next);
- if (node->next == NULL) goto fail;
- }
+ node->next = mds_kbdc_tree_dup(this->next);
+ fail_if (this->next && (node->next == NULL));
switch (this->type)
{
@@ -308,24 +311,15 @@ mds_kbdc_tree_t* mds_kbdc_tree_dup(mds_kbdc_tree_t* restrict this)
case C(FOR): { NODE(for); S(first);S(last);S(variable);T(inner); } break;
case C(IF): { NODE(if); S(condition);T(inner);T(otherwise); } break;
case C(MAP): { NODE(map); T(sequence);T(result); } break;
-
- case C(NOTHING):
- case C(RETURN):
- case C(BREAK):
- case C(CONTINUE):
- break;
-
default:
- abort();
break;
}
return node;
- fail:
+ pfail:
saved_errno = errno;
mds_kbdc_tree_free(node);
- errno = saved_errno;
- return NULL;
+ return errno = saved_errno, NULL;
}