]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Avoid asserts in output declarator traversal.
authorNick Bowler <nbowler@draconx.ca>
Wed, 21 Feb 2024 07:02:57 +0000 (02:02 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 22 Feb 2024 02:24:05 +0000 (21:24 -0500)
There is not a strong reason for an assert here.  With the assertion
removed, the consequence of an unexpected declarator type is that
nothing will be output for that declarator.  This is an acceptable
behaviour in and of itself, so let's just go with that.

src/declare.c
src/explain.c

index c5a1f236953a887a6d056b9dcf22f4b4e805fce2..ea6003f6c9a26c8cff0ca3d8206eabf74e132f8c 100644 (file)
@@ -17,9 +17,7 @@
  */
 
 #include <config.h>
-#include <stdio.h>
 #include <stdbool.h>
-#include <assert.h>
 
 #include "cdecl.h"
 #include "cdecl-internal.h"
@@ -124,8 +122,6 @@ declare_declarator(struct output_state *dst, struct cdecl_declarator *d)
                        declare_postfix_child(dst, d->child);
                        declare_function(dst, &d->u.function);
                        return;
-               default:
-                       assert(0);
                }
        }
 }
index 6d6aa87b76b83f9ae371e8758a841231cf3caf59..722e721f8ca114498c906927d9971ae88f3f4bec 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Render C declarations as English.
- *  Copyright © 2011, 2021, 2023 Nick Bowler
+ *  Copyright © 2011, 2021, 2023-2024 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -17,9 +17,7 @@
  */
 
 #include <config.h>
-#include <stdio.h>
 #include <inttypes.h>
-#include <assert.h>
 
 #include "cdecl.h"
 #include "cdecl-internal.h"
@@ -126,10 +124,8 @@ explain_function(struct output_state *dst, struct cdecl_function *f)
 static void
 explain_declarators(struct output_state *dst, struct cdecl_declarator *d)
 {
-       if (d->type == CDECL_DECL_IDENT || d->type == CDECL_DECL_NULL)
-               return;
-
-       explain_declarators(dst, d->child);
+       if (d->child)
+               explain_declarators(dst, d->child);
 
        switch (d->type) {
        case CDECL_DECL_POINTER:
@@ -141,8 +137,6 @@ explain_declarators(struct output_state *dst, struct cdecl_declarator *d)
        case CDECL_DECL_FUNCTION:
                explain_function(dst, &d->u.function);
                return;
-       default:
-               assert(0);
        }
 }