Deleted Added
full compact
emalloc.c (302408) emalloc.c (316068)
1/*
2 * emalloc - return new memory obtained from the system. Belch if none.
3 */
4#include <config.h>
5#include "ntp_types.h"
6#include "ntp_malloc.h"
7#include "ntp_syslog.h"
8#include "ntp_stdlib.h"

--- 69 unchanged lines hidden (view full) ---

78
79/*
80 * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
81 * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
82 */
83#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
84
85void *
1/*
2 * emalloc - return new memory obtained from the system. Belch if none.
3 */
4#include <config.h>
5#include "ntp_types.h"
6#include "ntp_malloc.h"
7#include "ntp_syslog.h"
8#include "ntp_stdlib.h"

--- 69 unchanged lines hidden (view full) ---

78
79/*
80 * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
81 * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
82 */
83#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
84
85void *
86oreallocarray(
86oreallocarrayxz(
87 void *optr,
88 size_t nmemb,
87 void *optr,
88 size_t nmemb,
89 size_t size
89 size_t size,
90 size_t extra
90#ifdef EREALLOC_CALLSITE /* ntp_malloc.h */
91 ,
92 const char * file,
93 int line
94#endif
95 )
96{
97 if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
98 nmemb > 0 && SIZE_MAX / nmemb < size) {
99#ifndef EREALLOC_CALLSITE
100 msyslog(LOG_ERR, "fatal allocation size overflow");
101#else
102 msyslog(LOG_ERR,
103 "fatal allocation size overflow %s line %d",
104 file, line);
105#endif
106 exit(1);
107 }
108#ifndef EREALLOC_CALLSITE
91#ifdef EREALLOC_CALLSITE /* ntp_malloc.h */
92 ,
93 const char * file,
94 int line
95#endif
96 )
97{
98 if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
99 nmemb > 0 && SIZE_MAX / nmemb < size) {
100#ifndef EREALLOC_CALLSITE
101 msyslog(LOG_ERR, "fatal allocation size overflow");
102#else
103 msyslog(LOG_ERR,
104 "fatal allocation size overflow %s line %d",
105 file, line);
106#endif
107 exit(1);
108 }
109#ifndef EREALLOC_CALLSITE
109 return ereallocz(optr, (size * nmemb), 0, FALSE);
110 return ereallocz(optr, extra + (size * nmemb), 0, TRUE);
110#else
111#else
111 return ereallocz(optr, (size * nmemb), 0, FALSE, file, line);
112 return ereallocz(optr, extra + (size * nmemb), 0, TRUE, file, line);
112#endif
113}
114
115char *
116estrdup_impl(
117 const char * str
118#ifdef EREALLOC_CALLSITE
119 ,

--- 30 unchanged lines hidden ---
113#endif
114}
115
116char *
117estrdup_impl(
118 const char * str
119#ifdef EREALLOC_CALLSITE
120 ,

--- 30 unchanged lines hidden ---