Two useless/empty bison reductions removed.
[splint-patched.git] / src / general.c
blob4ea33de3ca4917cfbc8d694f045375581fb5424d
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
15 **
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
25 ** general.c
28 # include "splintMacros.nf"
29 # include "basic.h"
31 # undef malloc
32 # undef realloc
33 # undef calloc
36 ** redefine undef'd memory ops
40 /*@-mustdefine@*/
43 ** all memory should be allocated from dimalloc
46 /*@out@*/ void *dimalloc (size_t size, const char *name, int line)
47 /*@ensures maxSet(result) == (size - 1); @*/
49 /* was malloc, use calloc to initialize to zero */
50 void *ret = (void *) calloc (1, size);
52 if (ret == NULL)
54 if (size == 0)
56 llcontbug (message ("Zero allocation at %q.",
57 fileloc_unparseRaw (cstring_fromChars (name), line)));
59 /*
60 ** evans 2002-03-01
61 ** Return some allocated storage...hope we get lucky.
64 return dimalloc (16, name, line);
66 else
68 /* drl fix this so message doesn't run out of memory*/
70 llbuglit("Out of memory");
72 llfatalerrorLoc
73 (message ("Out of memory. Allocating %w bytes at %s:%d.",
74 size_toLongUnsigned (size),
75 cstring_fromChars (name), line));
80 /*@-null@*/ /* null okay for size = 0 */
81 return ret;
82 /*@=null@*/
85 void *dicalloc (size_t num, size_t size, const char *name, int line)
87 void *ret = (void *) calloc (num, size);
89 if (ret == NULL)
91 llfatalerrorLoc
92 (message ("Out of memory. Allocating %w bytes at %s:%d.",
93 size_toLongUnsigned (size),
94 cstring_fromChars (name), line));
97 return ret;
100 void *direalloc (/*@out@*/ /*@null@*/ void *x, size_t size,
101 const char *name, int line)
103 void *ret;
105 if (x == NULL)
107 ret = (void *) dmalloc (size);
109 else
111 ret = (void *) realloc (x, size);
114 if (ret == NULL)
116 llfatalerrorLoc
117 (message ("Out of memory. Allocating %w bytes at %s:%d.",
118 size_toLongUnsigned (size),
119 cstring_fromChars (name), line));
122 return ret;
125 void sfreeEventually (void *x)
127 if (x != NULL)
129 ; /* should keep in a table */
131 /*@-mustfree@*/
132 } /*@=mustfree@*/
134 /*@=mustdefine@*/