From: Niels Möller Date: Sat, 7 Feb 2004 12:37:03 +0000 (+0100) Subject: (xalloc): New function. X-Git-Tag: nettle_1.9_release_20040207~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=785a6631719cb833c2a6e33fbc2a6d69d2cd7474;p=thirdparty%2Fnettle.git (xalloc): New function. (main): Use xalloc. Rev: src/nettle/tools/sexp-conv.c:1.15 --- 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);