Commit Graph

13 Commits

Author SHA1 Message Date
Eliseo Martínez
ddafdacb00 Use portable format specifiers: Case %lu - localized - EMSGU.
Problem  EMSGN was being used to print a format string using "%lu",
         which is incorrect because EMSGN casts its argument to int64_t.
Solution Use EMGSU instead.
2014-05-04 12:40:27 -04:00
Nicolas Hillegeer
6b486f41d1 memory: implement xstp(n)cpy
Both are implemented to POSIX 2008 spec, though I'm not sure I'm happy about
stpncpy's behaviour.
2014-04-29 09:29:10 -03:00
John Schmidt
4e1b364a3e Remove alloc_clear
Use `xcalloc` instead.
Inline `alloc_tv` and `alloc_string_tv` in eval.c
2014-04-28 07:41:45 -03:00
Felipe Oliveira Carvalho
15d8f702a8 (verbose_)?try_malloc() to use on buf_write()
There will be more use cases for try_malloc(): see #556.

 - Reimplemented xmalloc() using try_malloc().
 - verbose_try_malloc() is just like try_malloc() but shows an out-of-memory
	 error message before returning NULL.
 - Let the compiler generate size>>1 assembly for signed types. We're not using
	 old compilers here.
 - Add proper function attributes to the new functions in memory.h
2014-04-24 10:31:31 -03:00
Felipe Oliveira Carvalho
1befc49414 Use xmalloc() and xmemdupz() in file_pat_to_reg_pat()
Unfortunately there's still a case where NULL can be returned from
file_pat_to_reg_pat().

xmemdupz() and xmallocz() aren't static anymore. There are many use cases for
these function.
2014-04-24 10:31:31 -03:00
Eliseo Martínez
30b062e7d8 Use portable format specifiers: Case %lu - localized - EMSGN.
Fix uses of plain "%lu" within EMSGN():
- Replace "%lu" with "%" PRIu64.
- No argument cast needed. EMSGN() will take care of that.
2014-04-23 06:56:33 -03:00
John Schmidt
63cc8b6934 Remove lalloc_clear
Use `xcalloc` instead. Change some local variables
to avoid casting.
2014-04-19 09:36:17 -03:00
John Schmidt
3fcdb2ab29 Replace alloc_check by xmalloc
`alloc_check` is just a wrapper around xmalloc, so we can remove it and use
xmalloc directly. ref #487 / #488

The call was replaced in the following files:

- ex_cmds.c
- misc1.c
- ops.c
2014-04-10 17:03:50 -03:00
Thiago de Arruda
1fc7d6a0c5 Fix/add more files with to clint-files.txt 2014-04-08 13:49:45 -03:00
Felipe Oliveira Carvalho
fac85c1724 Implement xcalloc and use it in klist.h (use xrealloc as well)
Bonus: implement lalloc_clear and alloc_clear using xcalloc
2014-04-07 00:22:01 -03:00
Felipe Oliveira Carvalho
13848aadbf Remove simpler cases of OOM error handling (after *alloc calls)
By simpler cases I mean cases where the OOM error is not expected to be handled
by the caller of the function that calls `alloc`, `lalloc`, `xrealloc`,
`xmalloc`, `alloc_clear`, and `lalloc_clear`.

These are the functions that:

 - Do not return an allocated buffer
 - Have OOM as the only error condition

I took note of the functions that expect the caller to handle the OOM error and
will go through them to check all the callers that may be handling OOM error in
future commits.

I'm ignoring eval.c and ex_.c in this series of commits. eval.c will soon be
obsolete and I will deal with ex_.c in later PRs.
2014-04-06 22:54:59 -03:00
Thiago de Arruda
fdec1d126f Implement xstrdup and xstrndup
Utility functions for copying strings to newly-allocated chunks. They either
succeed or exit the program.
2014-04-06 11:32:47 -03:00
John Schmidt
6f53cb1cc3 Extract memory.c from misc2.c 2014-04-04 16:33:12 -03:00