]> Savannah Git Hosting - gnulib.git/commit
xmalloca, etc.: fix some xalloc-oversized issues
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 25 Apr 2021 00:59:53 +0000 (17:59 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 25 Apr 2021 01:00:47 +0000 (18:00 -0700)
commitcc98a5e2fd16ae8589deea9dbd71be59b6f77305
tree5cfda2d9701be2b35c5c8447f319402655188581
parenta7477abe2943c73bf23f39da2b706ea338d1c9b3
xmalloca, etc.: fix some xalloc-oversized issues

* lib/malloca.h (nmalloca):
* lib/xmalloca.h (xnmalloca): Convert S to ptrdiff_t to avoid
arithmetic overflow if N and S are both narrower than ptrdiff_t.
* lib/xalloc-oversized.h (xalloc_oversized):
Don’t say that args must be ptrdiff_t or size_t or wider.
The macro returns the correct answer even when that is not
the case, and it’s the caller’s responsibility to avoid
howlers like (xalloc_oversized (n, s) ? NULL : malloc (n * s))
when N and S are both narrower than ptrdiff_t and size_t.
Add a comment to that effect.
* lib/xmalloca.h: Include xalloc-oversized.h, since this file uses
xalloc_oversized.  Add comments about side effects and avoid
unnecessary parens.
* modules/xmalloca (Depends-on): Add xalloc-oversized.
ChangeLog
lib/malloca.h
lib/xalloc-oversized.h
lib/xmalloca.h
modules/xmalloca