parser: handle OOM gracefully
commit064e3f485714996a9a4c85acd32dd514f4481fd6
authorJim Meyering <meyering@redhat.com>
Wed, 20 Oct 2010 19:33:29 +0000 (20 21:33 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 21 Oct 2010 14:42:40 +0000 (21 16:42 +0200)
tree7e2f47981d699ac3f2dcb211472a0e3437f3b42b
parent2925ba08e51d0fb17df600da56c70e20627ab8e6
parser: handle OOM gracefully

Before, a failed malloc or strdup would lead to a NULL dereference.
* qparser.y (invalid): New file-scoped global.
(make_number): Never return NULL.  Instead, return &invalid.
(make_string): Likewise.
(make_tree): If an input has type T_INVALID, return it right away.
Upon allocation failure, return &invalid.
(make_comp, make_link): Likewise.
(make_link, make_string): Avoid unnecessary strdup, now that
lexed tokens are malloc'd.
Also, add some per-function comments.
qparser.y