[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/18] globs: Fix malloc() wrapper functions
From: |
Tim Hentenaar |
Subject: |
[PATCH 03/18] globs: Fix malloc() wrapper functions |
Date: |
Sat, 4 Jul 2015 13:43:17 +0200 |
Signed-off-by: Tim Hentenaar <address@hidden>
---
src/globs.c | 23 +++++++++--------------
src/globs.h | 22 +++++-----------------
2 files changed, 14 insertions(+), 31 deletions(-)
diff --git a/src/globs.c b/src/globs.c
index b89905f..941abc6 100644
--- a/src/globs.c
+++ b/src/globs.c
@@ -36,22 +36,20 @@ RCSTAG_CC ("$Id$");
* size_t, but not all systems have size_t, so I hope "unsigned" will work.
* It works for GNU style machines, where it is 32 bits, and works on
* MS-DOS. */
-
-extern char * xmalloc (
- unsigned size)
+extern void *xmalloc (unsigned int size)
{
- char *val = (char *) calloc (1, size);
+ void *val = calloc(1, size);
if (!val)
{
- fprintf (stderr, _("indent: Virtual memory exhausted.\n"));
- do_exit (system_error);
+ fprintf(stderr, _("indent: Virtual memory exhausted.\n"));
+ do_exit(system_error);
}
#if defined (DEBUG)
/* Fill it with garbage to detect code which depends on stuff being
zero-filled. */
- memset (val, 'x', size);
+ memset(val, 'x', size);
#endif
return val;
@@ -60,17 +58,14 @@ extern char * xmalloc (
/**
* Like realloc but get error if no storage available.
*/
-
-extern char *xrealloc (
- char *ptr,
- unsigned size)
+extern void *xrealloc(void *ptr, unsigned int size)
{
- char *val = (char *) realloc (ptr, size);
+ void *val = realloc(ptr, size);
if (!val)
{
- fprintf (stderr, _("indent: Virtual memory exhausted.\n"));
- exit (system_error);
+ fprintf(stderr, _("indent: Virtual memory exhausted.\n"));
+ do_exit(system_error);
}
return val;
diff --git a/src/globs.h b/src/globs.h
index bb81c76..5ecb7da 100644
--- a/src/globs.h
+++ b/src/globs.h
@@ -29,23 +29,11 @@ RCSTAG_H (globs, "$Id$");
#define ERROR(s, a, b) \
message (_("Error"), s, (unsigned int *)(a), (unsigned int *)(b))
-extern char *xmalloc(
- unsigned int size);
-
-extern char *xrealloc(
- char *ptr,
- unsigned int size);
-
-extern void xfree(
- void *ptr);
-
-extern void do_exit(
- int code);
-
-extern void fatal(
- const char *string,
- const char *a0);
-
+extern void *xmalloc(unsigned int size);
+extern void *xrealloc(void *ptr, unsigned int size);
+extern void xfree(void *ptr);
+extern void do_exit(int code);
+extern void fatal(const char *string, const char *a0);
extern void message(
char *kind,
char *string,
--
2.3.6
- [PATCH 00/18] Various fixes and improvements, Tim Hentenaar, 2015/07/04
- [PATCH 01/18] AM_CFLAGS: Add -ansi -pedantic and some warnings, Tim Hentenaar, 2015/07/04
- [PATCH 02/18] indent.h: Remove redundant extern declaration of else_or_endif, Tim Hentenaar, 2015/07/04
- [PATCH 03/18] globs: Fix malloc() wrapper functions,
Tim Hentenaar <=
- [PATCH 04/18] s/free/xfree/g, Tim Hentenaar, 2015/07/04
- [PATCH 05/18] Move need_chars into handletoken.c, Tim Hentenaar, 2015/07/04
- [PATCH 06/18] args: Compiler warning fixes, Tim Hentenaar, 2015/07/04
- [PATCH 07/18] gperf*.c: Fix compiler warnings, Tim Hentenaar, 2015/07/04
- [PATCH 08/18] texinfo2man: Fix potential buffer overruns and NULL pointer dereferences, Tim Hentenaar, 2015/07/04
- [PATCH 09/18] output.c: Remove dead code, Tim Hentenaar, 2015/07/04
- [PATCH 10/18] output.c: Fix potential NULL pointer dereferences, Tim Hentenaar, 2015/07/04
- [PATCH 11/18] output.c: Remove unused variable 'boolean_operator', Tim Hentenaar, 2015/07/04
- [PATCH 12/18] globs: Fix WARNING and ERROR macros to use char * instead of int *, Tim Hentenaar, 2015/07/04
- [PATCH 13/18] sys.h: Remove unused INLINE macro, Tim Hentenaar, 2015/07/04