~ubuntu-branches/ubuntu/utopic/nettle/utopic

« back to all changes in this revision

Viewing changes to realloc.c

  • Committer: Package Import Robot
  • Author(s): Magnus Holmgren
  • Date: 2013-05-07 22:57:14 UTC
  • mfrom: (8.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130507225714-s331yr8ov53dtt17
Tags: 2.7-2
Tag some (ECC related) symbols that only exist on some architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
/* nettle, low-level cryptographics library
6
6
 *
7
 
 * Copyright (C) 2002 Niels M�ller
 
7
 * Copyright (C) 2002 Niels Möller
8
8
 *  
9
9
 * The nettle library is free software; you can redistribute it and/or modify
10
10
 * it under the terms of the GNU Lesser General Public License as published by
18
18
 * 
19
19
 * You should have received a copy of the GNU Lesser General Public License
20
20
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
21
 
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22
 
 * MA 02111-1307, USA.
 
21
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
22
 * MA 02111-1301, USA.
23
23
 */
24
24
 
25
25
#if HAVE_CONFIG_H
31
31
 
32
32
#include "realloc.h"
33
33
 
 
34
/* NOTE: Calling libc realloc with size == 0 is not required to
 
35
   totally free the object, it is allowed to return a valid
 
36
   pointer. */
34
37
void *
35
38
nettle_realloc(void *ctx UNUSED, void *p, unsigned length)
36
39
{
37
 
  return realloc(p, length);
 
40
  if (length > 0)
 
41
    return realloc(p, length);
 
42
 
 
43
  free(p);
 
44
  return NULL;
38
45
}
39
46
 
40
47
void *
41
48
nettle_xrealloc(void *ctx UNUSED, void *p, unsigned length)
42
49
{
43
 
  void *n = realloc(p, length);
44
 
  if (length && !n)
 
50
  if (length > 0)
45
51
    {
46
 
      fprintf(stderr, "Virtual memory exhausted.\n");
47
 
      abort();
 
52
      void *n = realloc(p, length);
 
53
      if (!n)
 
54
        {
 
55
          fprintf(stderr, "Virtual memory exhausted.\n");
 
56
          abort();
 
57
        }
 
58
      return n;
48
59
    }
49
 
  return n;
 
60
  free(p);
 
61
  return NULL;
50
62
}