[augeas-devel] augeas: master - parser: report some allocation failures

David Lutterkort lutter at fedoraproject.org
Thu Oct 1 00:23:28 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=de27c8bb5718617b96b60fb0acf39ec9e47ae96e
Commit:        de27c8bb5718617b96b60fb0acf39ec9e47ae96e
Parent:        96c72991e324a87d11428e639ed868d4cb5c0b7d
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Tue Sep 29 17:10:37 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Sep 30 17:07:54 2009 -0700

parser: report some allocation failures

---
 src/parser.y |   22 ++++++++++++++--------
 src/syntax.c |    7 ++++---
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/parser.y b/src/parser.y
index 9230a29..3d13f43 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -18,7 +18,7 @@
 
 #define YYDEBUG 1
 
-int augl_parse_file(const char *name, struct term **term);
+int augl_parse_file(struct augeas *aug, const char *name, struct term **term);
 
 typedef void *yyscan_t;
 typedef struct info YYLTYPE;
@@ -304,7 +304,8 @@ tree_label: DQUOTED
             { $$ = NULL; }
 %%
 
-int augl_parse_file(const char *name, struct term **term) {
+int augl_parse_file(struct augeas *aug, const char *name,
+                    struct term **term) {
   yyscan_t       scanner;
   struct string  *sname = NULL;
   struct info    info;
@@ -313,14 +314,19 @@ int augl_parse_file(const char *name, struct term **term) {
 
   *term = NULL;
 
-  make_ref(sname);
+  r = make_ref(sname);
+  ERR_NOMEM(r < 0, aug);
+
   sname->str = strdup(name);
-  memset(&info, '\0', sizeof(info));
+  ERR_NOMEM(sname->str == NULL, aug);
+
+  MEMZERO(&info, 1);
   info.ref = UINT_MAX;
   info.filename = sname;
   if (augl_init_lexer(sname, &scanner) != 0) {
+    fprintf(stderr, "file name: %s [%s]\n", sname->str, name);
     augl_error(&info, term, NULL, "file not found");
-    goto done;
+    goto error;
   }
 
   yydebug = getenv("YYDEBUG") != NULL;
@@ -328,14 +334,14 @@ int augl_parse_file(const char *name, struct term **term) {
   augl_lex_destroy(scanner);
   if (r == 1) {
     augl_error(&info, term, NULL, "syntax error");
-    goto done;
+    goto error;
   } else if (r == 2) {
     augl_error(&info, term, NULL, "parser ran out of memory");
-    goto done;
+    ERR_NOMEM(1, aug);
   }
   result = 0;
 
- done:
+ error:
   unref(sname, string);
   // free TERM
   return result;
diff --git a/src/syntax.c b/src/syntax.c
index a429c75..b51703f 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -271,7 +271,8 @@ void free_value(struct value *v) {
  */
 struct term *make_term(enum term_tag tag, struct info *info) {
   struct term *term;
-  make_ref(term);
+  if (make_ref(term) < 0)
+      return NULL;
   term->tag = tag;
   if (info != NULL)
       term->info = info;
@@ -1793,7 +1794,7 @@ int define_native_intl(const char *file, int line,
 
 
 /* Defined in parser.y */
-int augl_parse_file(const char *name, struct term **term);
+int augl_parse_file(struct augeas *aug, const char *name, struct term **term);
 
 static char *module_basename(const char *modname) {
     char *fname;
@@ -1831,7 +1832,7 @@ int __aug_load_module_file(struct augeas *aug, const char *filename) {
     struct term *term = NULL;
     int result = -1;
 
-    if (augl_parse_file(filename, &term) == -1)
+    if (augl_parse_file(aug, filename, &term) == -1)
         goto error;
 
     if (! typecheck(term, aug))




More information about the augeas-devel mailing list