Commit 785a6631 authored by Niels Möller's avatar Niels Möller
Browse files

(xalloc): New function.

(main): Use xalloc.

Rev: src/nettle/tools/sexp-conv.c:1.15
parent de5c0855
...@@ -44,6 +44,19 @@ ...@@ -44,6 +44,19 @@
#define BUG_ADDRESS "nettle-bugs@lists.lysator.liu.se" #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. */ /* Conversion functions. */
...@@ -318,7 +331,7 @@ main(int argc, char **argv) ...@@ -318,7 +331,7 @@ main(int argc, char **argv)
struct sexp_parser parser; struct sexp_parser parser;
struct sexp_compound_token token; struct sexp_compound_token token;
struct sexp_output output; struct sexp_output output;
parse_options(&options, argc, argv); parse_options(&options, argc, argv);
sexp_input_init(&input, stdin); sexp_input_init(&input, stdin);
...@@ -328,9 +341,11 @@ main(int argc, char **argv) ...@@ -328,9 +341,11 @@ main(int argc, char **argv)
options.width, options.prefer_hex); options.width, options.prefer_hex);
if (options.hash) if (options.hash)
sexp_output_hash_init(&output, {
options.hash, /* Leaks the context, but that doesn't matter */
alloca(options.hash->context_size)); void *ctx = xalloc(options.hash->context_size);
sexp_output_hash_init(&output, options.hash, ctx);
}
sexp_get_char(&input); sexp_get_char(&input);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment