From 785a6631719cb833c2a6e33fbc2a6d69d2cd7474 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Sat, 7 Feb 2004 13:37:03 +0100
Subject: [PATCH] (xalloc): New function. (main): Use xalloc.

Rev: src/nettle/tools/sexp-conv.c:1.15
---
 tools/sexp-conv.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/sexp-conv.c b/tools/sexp-conv.c
index 0d614063..d4b152b6 100644
--- a/tools/sexp-conv.c
+++ b/tools/sexp-conv.c
@@ -44,6 +44,19 @@
 
 #define BUG_ADDRESS "nettle-bugs@lists.lysator.liu.se"
 
+static void *
+xalloc(size_t size)
+{
+  void *p = malloc(size);
+  if (!p)
+    {
+      fprintf(stderr, "Virtual memory exhausted.\n");
+      abort();
+    }
+
+  return p;
+}
+
 
 /* Conversion functions. */
 
@@ -318,7 +331,7 @@ main(int argc, char **argv)
   struct sexp_parser parser;
   struct sexp_compound_token token;
   struct sexp_output output;
-  
+
   parse_options(&options, argc, argv);
 
   sexp_input_init(&input, stdin);
@@ -328,9 +341,11 @@ main(int argc, char **argv)
 		   options.width, options.prefer_hex);
 
   if (options.hash)
-    sexp_output_hash_init(&output,
-			  options.hash,
-			  alloca(options.hash->context_size));
+    {
+      /* Leaks the context, but that doesn't matter */
+      void *ctx = xalloc(options.hash->context_size);
+      sexp_output_hash_init(&output, options.hash, ctx);
+    }
   
   sexp_get_char(&input);
   
-- 
GitLab