aboutsummaryrefslogtreecommitdiff
path: root/src/sc_parse.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-01-18 22:53:55 +0100
committerThomas White <taw@physics.org>2018-01-18 22:53:55 +0100
commit7b0d0bf3e125018e1cf191ec36e823d797a91f8c (patch)
treed46415be71632855f914a82f614dc4c212b4bf1d /src/sc_parse.c
parent53830f66ca3cd8573340b4f43945aeedf60e5f5f (diff)
sc_block_delete/unlink: Pass error condition back up if parent block can't be found
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r--src/sc_parse.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c
index a8b2c09..39f6ad5 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -243,7 +243,7 @@ void sc_block_substitute(SCBlock **top, SCBlock *old, SCBlock *new)
/* Unlink "deleteme", which is somewhere under "top" */
-void sc_block_unlink(SCBlock **top, SCBlock *deleteme)
+int sc_block_unlink(SCBlock **top, SCBlock *deleteme)
{
SCBlock *parent = sc_find_parent(*top, deleteme);
if ( parent == NULL ) {
@@ -251,10 +251,11 @@ void sc_block_unlink(SCBlock **top, SCBlock *deleteme)
if ( *top == deleteme ) {
fprintf(stderr, "Unlinking at top\n");
*top = (*top)->next;
+ return 0;
} else {
fprintf(stderr, "Couldn't find block parent!\n");
+ return 1;
}
- return;
}
if ( parent->next == deleteme ) {
@@ -264,14 +265,19 @@ void sc_block_unlink(SCBlock **top, SCBlock *deleteme)
if ( parent->child == deleteme ) {
parent->child = NULL;
}
+ return 0;
}
/* Delete "deleteme", which is somewhere under "top" */
-void sc_block_delete(SCBlock **top, SCBlock *deleteme)
+int sc_block_delete(SCBlock **top, SCBlock *deleteme)
{
- sc_block_unlink(top, deleteme);
- sc_block_free(deleteme);
+ int r;
+ r = sc_block_unlink(top, deleteme);
+ if ( !r ) {
+ sc_block_free(deleteme);
+ }
+ return r;
}