summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2018-01-07 18:33:56 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2018-01-07 18:33:56 (GMT)
commit8c68d2a748ce641209d4e4a142a14ca2b0477c5a (patch) (side-by-side diff)
tree50abf32d61d790263817f3e563f27f62d61c437a
parent14ec080ad440a76234a89f8d8a058eac6d3fe4eb (diff)
downloadfileserv-8c68d2a748ce641209d4e4a142a14ca2b0477c5a.tar.gz
fileserv-8c68d2a748ce641209d4e4a142a14ca2b0477c5a.tar.bz2
Uniformly handle out of memory conditions
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--mimetypes/err.c7
-rw-r--r--mimetypes/grammar.y8
-rw-r--r--mimetypes/lexer.l8
-rw-r--r--mimetypes/linetrack.c6
-rw-r--r--mimetypes/mtint.h1
5 files changed, 21 insertions, 9 deletions
diff --git a/mimetypes/err.c b/mimetypes/err.c
index 39f25a5..01164c9 100644
--- a/mimetypes/err.c
+++ b/mimetypes/err.c
@@ -148,3 +148,10 @@ print_locus_range (FILE *fp, struct locus_range const *lr)
fwrite (buf, buflen, 1, fp);
free (buf);
}
+
+void
+mimetypes_nomem (void)
+{
+ mimetypes_error_printer ("out of memory");
+ abort ();
+}
diff --git a/mimetypes/grammar.y b/mimetypes/grammar.y
index 2ae1997..2ddc1fd 100644
--- a/mimetypes/grammar.y
+++ b/mimetypes/grammar.y
@@ -55,6 +55,8 @@ arg_list_append (struct arg_list *al, struct mimetypes_string const *str)
{
struct arg_elt *elt;
elt = malloc (sizeof *elt);
+ if (!elt)
+ mimetypes_nomem ();
elt->string.ptr = str->ptr;
elt->string.len = str->len;
LLE_APPEND (al, elt, link);
@@ -126,6 +128,8 @@ rule_line: /* empty */
| TYPE maybe_rule maybe_priority
{
struct rule *p = malloc (sizeof (*p));
+ if (!p)
+ mimetypes_nomem ();
LLE_APPEND (&rule_list, p, link);
p->type = $1.ptr;
p->node = $2;
@@ -271,6 +275,8 @@ static struct node *
make_node (enum node_type type, struct locus_range const *loc)
{
struct node *p = malloc (sizeof *p);
+ if (!p)
+ mimetypes_nomem ();
p->type = type;
locus_range_init (&p->loc);
locus_range_copy (&p->loc, loc);
@@ -339,6 +345,8 @@ make_functional_node (char *ident, struct arg_list *list,
}
args = calloc (count, sizeof *args);
+ if (!args)
+ mimetypes_nomem ();
i = 0;
LL_FOREACH (list, elt, link)
{
diff --git a/mimetypes/lexer.l b/mimetypes/lexer.l
index 568a5cf..1e4c8ac 100644
--- a/mimetypes/lexer.l
+++ b/mimetypes/lexer.l
@@ -49,7 +49,7 @@ string_moremem (size_t size)
}
string_buffer = realloc (string_buffer, string_size);
if (!string_buffer)
- abort ();
+ mimetypes_nomem ();
}
}
@@ -87,7 +87,7 @@ finish_string (void)
{
yylval.string.ptr = malloc (string_level + 1);
if (!yylval.string.ptr)
- abort ();
+ mimetypes_nomem ();
memcpy (yylval.string.ptr, string_buffer, string_level);
yylval.string.ptr[string_level] = 0;
yylval.string.len = string_level;
@@ -99,7 +99,7 @@ finish_astring (void)
{
yylval.string.ptr = malloc (string_level + 1);
if (!yylval.string.ptr)
- abort ();
+ mimetypes_nomem ();
memcpy (yylval.string.ptr, string_buffer, string_level);
yylval.string.ptr[string_level] = 0;
yylval.string.len = string_level;
@@ -284,7 +284,7 @@ mimetypes_open (const char *name)
abort ();
filename = malloc (blen + 1 + strlen (fname) + 1);
if (!filename)
- abort ();
+ mimetypes_nomem ();
strcpy (filename, name);
strcat (filename, "/");
strcat (filename, fname);
diff --git a/mimetypes/linetrack.c b/mimetypes/linetrack.c
index 90754ea..dda1636 100644
--- a/mimetypes/linetrack.c
+++ b/mimetypes/linetrack.c
@@ -365,11 +365,7 @@ linetrack_retreat (struct linetrack *trk, size_t n)
{
ptr = pop (trk);
if (!ptr || *ptr == 0)
- {
- mimetypes_error ("%s:%d: INTERNAL ERROR: out of pop back\n",
- __FILE__, __LINE__);
- return ERANGE;
- }
+ return ERANGE;
}
--*ptr;
}
diff --git a/mimetypes/mtint.h b/mimetypes/mtint.h
index 0458e4d..a3324d1 100644
--- a/mimetypes/mtint.h
+++ b/mimetypes/mtint.h
@@ -157,6 +157,7 @@ ssize_t mimetypes_error_format (char **pbuf, size_t *psize,
void mimetypes_error_at (struct locus_range const *lr, char const *fmt, ...);
void mimetypes_error (char const *fmt, ...);
void print_locus_range (FILE *fp, struct locus_range const *lr);
+void mimetypes_nomem (void);
int mimetypes_open (const char *name);
void mimetypes_close (void);

Return to:

Send suggestions and report system problems to the System administrator.