On Tue, Apr 07, 2015 at 12:40:35AM +0900, Masatake YAMATO wrote:
> --- a/defs.h
> +++ b/defs.h
> @@ -434,6 +434,15 @@ void perror_msg_and_die(const char *fmt, ...)
>       ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
>  void die_out_of_memory(void) ATTRIBUTE_NORETURN;
>  
> +/*
> + * Memory allocator + die_out_of_memory
> + */
> +void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
> +void *xcalloc(size_t nmmeb, size_t size)
> +     ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
> +void *xreallocarray(void *optr, size_t nmemb, size_t size)
> +     ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));

ATTRIBUTE_MALLOC is not applicable for realloc.

> --- /dev/null
> +++ b/xmalloc.c
> @@ -0,0 +1,92 @@
> +/*
> + * Copyright (c) 1991, 1992 Paul Kranenburg <p...@cs.few.eur.nl>
> + * Copyright (c) 1993 Branko Lankester <bra...@hacktic.nl>
> + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <j...@world.std.com>
> + * Copyright (c) 1996-1999 Wichert Akkerman <wich...@cistron.nl>

Not sure these honored people have anything to do with this new code.

> +/* (part of xreallocarray is derived from reallocarray)

Which one?  The definition of MUL_NO_OVERFLOW?

> + *
> + * About reallocarray
> + *
> + * Copyright (c) 2008 Otto Moerbeek <o...@drijf.net>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +/*
> + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
> + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
> + */
> +#define MUL_NO_OVERFLOW      ((size_t)1 << (sizeof(size_t) * 4))
> +
> +void *
> +xreallocarray(void *optr, size_t nmemb, size_t size)
> +{
> +     void *r;
> +     size_t bytes = nmemb * size;
> +
> +     if (((nmemb | size) >= MUL_NO_OVERFLOW) &&
> +         size && bytes / size != nmemb)
> +             die_out_of_memory();
> +
> +
> +     r = realloc(optr, size * nmemb);

"bytes" already contains the result of multiplication.


-- 
ldv

Attachment: pgpaOj34wT1V6.pgp
Description: PGP signature

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to