Commit Graph

9 Commits

Author SHA1 Message Date
Eugene Syromiatnikov
057a8f2274 xmalloc.c: introduce xgrowarray helper function
In order to simplify dynamic array management code.

* xmalloc.h (xgrowarray): New declaration.
* xmalloc.c (xgrowarray): New function.
2017-12-14 00:05:04 +00:00
Eugene Syromyatnikov
dc3dfc68b4 Update copyright headers
Headers updated automatically with

    maint/update_copyright_headers.sh -c
2017-09-05 10:09:10 +02:00
Eugene Syromiatnikov
7ba0d89c9f xstrdup, xtrndup: allow NULL argument
Accept NULL argument in xstrdup and xtrndup functions to allow use
of "xstrdup(str)" instead of "str ? xstrdup(str) : NULL".

* xmalloc.c (xstrdup, xstrndup): Handle NULL argument.
* xmalloc.h: Add comment regarding this deviation from the behaviour
of the POSIX counterparts of these functions.
2017-08-24 20:06:54 +02:00
Edgar Kaziakhmedov
b4f16886e7 Move err/mem subroutines to separate files
In order to allow usage of utility functions by other binaries
included in the strace package (like the upcoming asinfo utility),
these functions should be moved to separate files.

* error_prints.h: New file.
* xmalloc.h: Likewise.
* defs.h: Include "xmalloc.h" and "error_prints.h".
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die): Move to error_prints.h.
(xcalloc, xmalloc, xreallocarray, xstrdup, xstrndup): Move to xmalloc.h.
* strace.c (die): Remove static quialifier to make visible
by error_prints.c.
(error_msg, error_msg_and_die, error_msg_and_help, perror_msg,
perror_msg_and_die, verror_msg): Move ...
* error_prints.c: ... to the new file.
* xmalloc.c: Include "config.h", <stdlib.h>, <string.h>,
"error_prints.h", and "xmalloc.h" instead of "defs.h".
Use int instead of bool.  Fix codestyle.
* Makefile.am (strace_SOURCES): Add error_prints.c, error_prints.h,
and xmalloc.h.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-08-07 10:59:22 +00:00
2698d1d060 Unexport die_out_of_memory
Print more specific error diagnostics than a generic "Out of memory"
when an error happens outside xmalloc.c.

* defs.h (die_out_of_memory): Remove prototype.
* strace.c (strace_popen, init): Call perror_msg_and_die instead
of die_out_of_memory.
* unwind.c (unwind_tcb_init): Likewise.
* xmalloc.c (die_out_of_memory): Add static qualifier.
2017-06-26 22:41:28 +00:00
Masatake YAMATO
d10d64820f Introduce xstrndup function
* configure.ac (AC_CHECK_FUNCS): Add strndup.
* defs.h (xstrndup): New prototype.
* xmalloc.c (xstrndup): New function.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2017-06-19 21:45:58 +00:00
3baf7ef953 Fix a few initialization style issues
Do not initialise statics and globals to 0, NULL, or false.

Reported by kernel's checkpatch.pl script.
2017-06-17 20:49:09 +00:00
38a34c9349 Add copyright headers to some files which lack them
Before this change, all files that exist since 20th century had
copyright headers, while most files that appeared later didn't.  This
change fixes the inconsistency by adding missing copyright headers.

It doesn't mean that copyright headers became maintained.  In my view,
git history provides much better information on this subject and is much
more accurate than copyright headers.
2015-12-17 17:56:48 +00:00
3e9d71feaa Introduce memory allocation wrappers
Introduce wrappers to the following functions that do memory allocation:
malloc, calloc, realloc, strdup.

This commit is a follow-up to the related discussions in strace-devel ML:
http://sourceforge.net/p/strace/mailman/message/33618180/
http://sourceforge.net/p/strace/mailman/message/33733470/

* defs.h (xmalloc, xcalloc, xreallocarray, xstrdup): New prototypes.
* xmalloc.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* count.c (count_syscall, call_summary_pers): Use xcalloc.
* desc.c (decode_select): Use xmalloc.
* dirent.c (sys_getdents, sys_getdents64): Likewise.
* net.c (sys_recvmmsg): Use xstrdup.
* pathtrace.c (storepath): Use xreallocarray.
(pathtrace_match): Use xmalloc.
* strace.c (die_out_of_memory): Move to xmalloc.c.
(expand_tcbtab): Use xcalloc and xreallocarray.
(startup_child): Use xstrdup.
(init): Use xmalloc, xcalloc, and xstrdup.
* syscall.c (reallocate_qual): Use xreallocarray.
(qualify): Use xstrdup.
* unwind.c (unwind_tcb_init): Use xmalloc.
(build_mmap_cache): Use xcalloc, xreallocarray, and xstrdup.
(get_symbol_name): Use xreallocarray.
(stacktrace_walk, queue_put): Use xmalloc.
* util.c (printstr): Use xmalloc.
* vsprintf.c (strace_vfprintf): Likewise.
2015-05-25 22:25:22 +00:00