Commit d5b955f07f6d39f177a2cc9274f57afba623f4e7

Thomas de Grivel 2024-07-06T13:45:42

error handling

diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 8e24f9f..f1f1a52 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -793,9 +793,14 @@ sw buf_parse_call_op (s_buf *buf, s_call *dest)
   assert(buf);
   assert(dest);
   buf_save_init(buf, &save);
-  call_init_op(&tmp);
-  if ((r = buf_parse_tag_primary(buf, &tmp.arguments->tag)) <= 0)
-    goto restore;
+  if (! call_init_op(&tmp)) {
+    r = -1;
+    goto clean;
+  }
+  if ((r = buf_parse_tag_primary(buf, &tmp.arguments->tag)) <= 0) {
+    call_clean(&tmp);
+    goto clean;
+  }
   result += r;
   if ((r = buf_ignore_spaces_but_newline(buf)) < 0)
     goto restore;
diff --git a/libc3/call.c b/libc3/call.c
index 4daad57..313ef45 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -123,7 +123,7 @@ s_call * call_init_copy (s_call *call, const s_call *src)
       ! list_init_copy(&tmp.arguments,
                        (const s_list * const *) &src->arguments))
     return NULL;
-  // TODO: copy cfn and fn ?
+  // FIXME: copy cfn and fn ?
   tmp.cfn = src->cfn;
   tmp.fn = src->fn;
   *call = tmp;
@@ -132,9 +132,17 @@ s_call * call_init_copy (s_call *call, const s_call *src)
 
 s_call * call_init_op (s_call *call)
 {
+  s_list *arg;
   s_call tmp = {0};
   assert(call);
-  tmp.arguments = list_new(list_new(NULL));
+  arg = list_new(NULL);
+  if (! arg)
+    return NULL;
+  tmp.arguments = list_new(arg);
+  if (! tmp.arguments) {
+    list_delete(arg);
+    return NULL;
+  }
   *call = tmp;
   return call;
 }