This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project iwhd.git.
The branch, master has been updated
via f4d05852a6185b36660f5feee44cdb82ccba7b32 (commit)
via c98f5c1f712ca5b35cbaef83d2ea47015687e68c (commit)
via e6a29d3e5890a27c8f3afae96b8d5a2cf6cbaed6 (commit)
via 064e3f485714996a9a4c85acd32dd514f4481fd6 (commit)
from 2925ba08e51d0fb17df600da56c70e20627ab8e6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://repo.or.cz/w/iwhd.git/commit/f4d05852a6185b36660f5feee44cdb82ccba7b32
commit f4d05852a6185b36660f5feee44cdb82ccba7b32
Author: Jim Meyering <meyering(a)redhat.com>
Date: Thu Oct 21 09:08:39 2010 +0200
reduce scope of global to be file-only
* qparser.y (hacked_links): Declare to be "static const".
diff --git a/qparser.y b/qparser.y
index a23b5a7..1c6530a 100644
--- a/qparser.y
+++ b/qparser.y
@@ -329,7 +329,7 @@ unit_sget_func (void * notused, const char *text)
static const getter_t unit_sget = { unit_sget_func };
/* Fake links from an object/key tuple to an object/key string. */
-struct { char *obj; char *key; char *value; } hacked_links[] = {
+static const struct { char *obj; char *key; char *value; } hacked_links[] = {
{ "templates/the_tmpl", "owner", "users/the_user" },
{ "users/the_user", "name", "Jeff Darcy" },
{ NULL }
http://repo.or.cz/w/iwhd.git/commit/c98f5c1f712ca5b35cbaef83d2ea47015687e68c
commit c98f5c1f712ca5b35cbaef83d2ea47015687e68c
Author: Jim Meyering <meyering(a)redhat.com>
Date: Wed Oct 20 21:36:37 2010 +0200
parser: move x*alloc functions into #if-unit-test block where used
* qparser.y (xalloc_die, xmalloc, xmemdup, xstrdup): Move functions...
[#if PARSER_UNIT_TEST]: ... into this #if-block, since now they're
used only there.
diff --git a/qparser.y b/qparser.y
index cb6d36e..a23b5a7 100644
--- a/qparser.y
+++ b/qparser.y
@@ -28,44 +28,6 @@ static value_t invalid = { T_INVALID, {0}, NULL };
#define YY_DECL int yylex(YYSTYPE *, void *scanner);
YY_DECL
-static void
-xalloc_die (void)
-{
- error (EXIT_FAILURE, 0, "%s", "memory exhausted");
-
- /* The `noreturn' cannot be given to error, since it may return if
- its first argument is 0. To help compilers understand the
- xalloc_die does not return, call abort. Also, the abort is a
- safety feature if exit_failure is 0 (which shouldn't happen). */
- abort ();
-}
-
-/* Allocate N bytes of memory dynamically, with error checking. */
-static void *
-xmalloc (size_t n)
-{
- void *p = malloc (n);
- if (!p && n != 0)
- xalloc_die ();
- return p;
-}
-
-/* Clone an object P of size S, with error checking. There's no need
- for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
- need for an arithmetic overflow check. */
-static void *
-xmemdup (void const *p, size_t s)
-{
- return memcpy (xmalloc (s), p, s);
-}
-
-/* Clone STRING. */
-static char *
-xstrdup (char const *string)
-{
- return xmemdup (string, strlen (string) + 1);
-}
-
/* TBD: use separate function to parse dates differently */
static value_t *
make_number (const char *text)
@@ -292,6 +254,45 @@ paren_expr:
%%
#if defined PARSER_UNIT_TEST
+
+static void
+xalloc_die (void)
+{
+ error (EXIT_FAILURE, 0, "%s", "memory exhausted");
+
+ /* The `noreturn' cannot be given to error, since it may return if
+ its first argument is 0. To help compilers understand the
+ xalloc_die does not return, call abort. Also, the abort is a
+ safety feature if exit_failure is 0 (which shouldn't happen). */
+ abort ();
+}
+
+/* Allocate N bytes of memory dynamically, with error checking. */
+static void *
+xmalloc (size_t n)
+{
+ void *p = malloc (n);
+ if (!p && n != 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Clone an object P of size S, with error checking. There's no need
+ for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
+ need for an arithmetic overflow check. */
+static void *
+xmemdup (void const *p, size_t s)
+{
+ return memcpy (xmalloc (s), p, s);
+}
+
+/* Clone STRING. */
+static char *
+xstrdup (char const *string)
+{
+ return xmemdup (string, strlen (string) + 1);
+}
+
static const struct { char *name; char *value; } hacked_obj_fields[] = {
/* Fake object fields for generic unit testing. */
{ "a", "2" }, { "b", "7" }, { "c",
"11" },
http://repo.or.cz/w/iwhd.git/commit/e6a29d3e5890a27c8f3afae96b8d5a2cf6cbaed6
commit e6a29d3e5890a27c8f3afae96b8d5a2cf6cbaed6
Author: Jim Meyering <meyering(a)redhat.com>
Date: Wed Oct 20 21:34:08 2010 +0200
parser: remove dead code
* qparser.y (xrealloc): Remove if-0'd function.
diff --git a/qparser.y b/qparser.y
index 82b5125..cb6d36e 100644
--- a/qparser.y
+++ b/qparser.y
@@ -50,19 +50,6 @@ xmalloc (size_t n)
return p;
}
-#if 0 // not used
-/* Change the size of an allocated block of memory P to N bytes,
- with error checking. */
-static void *
-xrealloc (void *p, size_t n)
-{
- p = realloc (p, n);
- if (!p && n != 0)
- xalloc_die ();
- return p;
-}
-#endif
-
/* Clone an object P of size S, with error checking. There's no need
for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
need for an arithmetic overflow check. */
http://repo.or.cz/w/iwhd.git/commit/064e3f485714996a9a4c85acd32dd514f4481fd6
commit 064e3f485714996a9a4c85acd32dd514f4481fd6
Author: Jim Meyering <meyering(a)redhat.com>
Date: Wed Oct 20 21:33:29 2010 +0200
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.
diff --git a/qparser.y b/qparser.y
index 99267c4..82b5125 100644
--- a/qparser.y
+++ b/qparser.y
@@ -21,6 +21,10 @@
#include "iwh.h"
+/* Return a pointer to this when allocation fails in a value_t-returning
+ function. */
+static value_t invalid = { T_INVALID, {0}, NULL };
+
#define YY_DECL int yylex(YYSTYPE *, void *scanner);
YY_DECL
@@ -80,71 +84,79 @@ static value_t *
make_number (const char *text)
{
value_t *tmp = malloc(sizeof(*tmp));
+ if (!tmp)
+ return &invalid;
- if (tmp) {
- tmp->type = T_NUMBER;
- tmp->as_num = strtoll(text,NULL,10);
- tmp->resolved = NULL;
- }
+ tmp->type = T_NUMBER;
+ tmp->as_num = strtoll(text,NULL,10);
+ tmp->resolved = NULL;
free ((void *) text);
return tmp;
}
+/* Return a malloc'd value_t buffer, with its type to T and using TEXT
+ (already malloc'd) as its string. */
static value_t *
make_string (const char *text, type_t t)
{
value_t *tmp = malloc(sizeof(*tmp));
+ if (!tmp)
+ return &invalid;
- if (tmp) {
- tmp->type = t;
- tmp->as_str = xstrdup(text);
- tmp->resolved = NULL;
- }
- free ((void *) text);
+ tmp->type = t;
+ tmp->as_str = (char *) text;
+ tmp->resolved = NULL;
return tmp;
}
+/* Return a malloc'd tree_t, with type T and branches LEFT and RIGHT.
+ LEFT must be non-NULL. RIGHT may be NULL (solely for use in handling
+ a negated expression). */
static value_t *
make_tree (type_t t, const value_t *left, const value_t *right)
{
+ if (left->type == T_INVALID)
+ return (value_t *) left;
+ if (t != T_LINK && right && right->type == T_INVALID)
+ return (value_t *) right;
value_t *tmp = malloc(sizeof(*tmp));
- if (tmp) {
- tmp->type = t;
- tmp->as_tree.left = (value_t *) left;
- tmp->as_tree.right = (value_t *) right;
- tmp->resolved = NULL;
- }
+ if (!tmp)
+ return &invalid;
+
+ tmp->type = t;
+ tmp->as_tree.left = (value_t *) left;
+ tmp->as_tree.right = (value_t *) right;
+ tmp->resolved = NULL;
return tmp;
}
+/* Return a malloc'd comp_t, with type T and branches LEFT and RIGHT.
+ LEFT and RIGHT must both be non-NULL. */
static value_t *
make_comp (comp_t c, const value_t *left, const value_t *right)
{
+ if (left->type == T_INVALID)
+ return (value_t *) left;
+ if (right->type == T_INVALID)
+ return (value_t *) right;
value_t *tmp = make_tree(T_COMP,left,right);
- if (tmp) {
- tmp->as_tree.op = c;
- }
+ if (!tmp)
+ return &invalid;
+
+ tmp->as_tree.op = c;
return tmp;
}
static value_t *
-make_link (value_t *left, const char *right)
+make_link (const value_t *left, const char *right)
{
- char *copy;
-
- copy = xstrdup(right);
- free ((void *) right);
- if (!copy) {
- return NULL;
- }
-
- return make_tree(T_LINK,left,(value_t *)copy);
+ return make_tree(T_LINK,left,(value_t *)right);
}
static void
-----------------------------------------------------------------------
Summary of changes:
qparser.y | 164 ++++++++++++++++++++++++++++++------------------------------
1 files changed, 82 insertions(+), 82 deletions(-)
repo.or.cz automatic notification. Contact project admin jim(a)meyering.net
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
iwhd.git ("image warehouse daemon")