void *p;
p = _safe_emalloc(nmemb, size, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
- if (UNEXPECTED(p == NULL)) {
- return p;
- }
memset(p, 0, size * nmemb);
return p;
}
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
}
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
- if (UNEXPECTED(p == NULL)) {
- return p;
- }
memcpy(p, s, length+1);
return p;
}
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (1 * %zu + 1)", length);
}
p = (char *) _emalloc(length + 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
- if (UNEXPECTED(p == NULL)) {
- return p;
- }
memcpy(p, s, length);
p[length] = 0;
return p;
*length = 1;
retval = (char *) emalloc(2);
- if (retval == NULL) {
- return NULL;
- }
retval[0] = DEFAULT_SLASH;
retval[1] = '\0';
return retval;
*length = state->cwd_length+1;
retval = (char *) emalloc(*length+1);
- if (retval == NULL) {
- return NULL;
- }
memcpy(retval, state->cwd, *length);
retval[0] = toupper(retval[0]);
retval[*length-1] = DEFAULT_SLASH;
state->cwd_length = path_length;
tmp = erealloc(state->cwd, state->cwd_length+1);
- if (tmp == NULL) {
- CWD_STATE_FREE(&old_state);
-#if VIRTUAL_CWD_DEBUG
- fprintf (stderr, "Out of memory\n");
-#endif
- return 1;
- }
state->cwd = (char *) tmp;
memcpy(state->cwd, resolved_path, state->cwd_length+1);
} else {
state->cwd_length = path_length;
tmp = erealloc(state->cwd, state->cwd_length+1);
- if (tmp == NULL) {
-#if VIRTUAL_CWD_DEBUG
- fprintf (stderr, "Out of memory\n");
-#endif
- return 1;
- }
state->cwd = (char *) tmp;
memcpy(state->cwd, resolved_path, state->cwd_length+1);
/* realpath("") returns CWD */
if (!*path) {
new_state.cwd = (char*)emalloc(1);
- if (new_state.cwd == NULL) {
- retval = NULL;
- goto end;
- }
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
CWD_STATE_COPY(&new_state, &CWDG(cwd));
} else {
new_state.cwd = (char*)emalloc(1);
- if (new_state.cwd == NULL) {
- retval = NULL;
- goto end;
- }
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
}
}
CWD_STATE_FREE(&new_state);
-end:
return retval;
}
/* }}} */
dir = CWDG(cwd).cwd;
ptr = command_line = (char *) emalloc(command_length + sizeof("cd '' ; ") + dir_length + extra+1+1);
- if (!command_line) {
- return NULL;
- }
memcpy(ptr, "cd ", sizeof("cd ")-1);
ptr += sizeof("cd ")-1;
/* realpath("") returns CWD */
if (!*path) {
new_state.cwd = (char*)emalloc(1);
- if (new_state.cwd == NULL) {
- return NULL;
- }
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
new_state.cwd_length = (int)strlen(cwd);
} else {
new_state.cwd = (char*)emalloc(1);
- if (new_state.cwd == NULL) {
- return NULL;
- }
new_state.cwd[0] = '\0';
new_state.cwd_length = 0;
}
else
extra = 0;
num1 = (unsigned char *) safe_emalloc (1, n1->n_len+n1->n_scale, extra+2);
- if (num1 == NULL) bc_out_of_memory();
memset (num1, 0, n1->n_len+n1->n_scale+extra+2);
memcpy (num1+1, n1->n_value, n1->n_len+n1->n_scale);
len2 = n2->n_len + scale2;
num2 = (unsigned char *) safe_emalloc (1, len2, 1);
- if (num2 == NULL) bc_out_of_memory();
memcpy (num2, n2->n_value, len2);
*(num2+len2) = 0;
n2ptr = num2;
/* Allocate storage for the temporary storage mval. */
mval = (unsigned char *) safe_emalloc (1, len2, 1);
- if (mval == NULL) bc_out_of_memory ();
/* Now for the full divide algorithm. */
if (!zero)
_bc_Free_list = temp->n_next;
} else {
temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
- if (temp == NULL) bc_out_of_memory ();
}
#endif
temp->n_sign = PLUS;
temp->n_refs = 1;
/* PHP Change: malloc() -> pemalloc() */
temp->n_ptr = (char *) safe_pemalloc (1, length, scale, persistent);
- if (temp->n_ptr == NULL) bc_out_of_memory();
temp->n_value = temp->n_ptr;
memset (temp->n_ptr, 0, length+scale);
return temp;
bc_modulo (int_part, base, &cur_dig, 0);
/* PHP Change: malloc() -> emalloc() */
temp = (stk_rec *) emalloc (sizeof(stk_rec));
- if (temp == NULL) bc_out_of_memory();
temp->digit = bc_num2long (cur_dig);
temp->next = digits;
digits = temp;
const char *to_charset, size_t to_charset_len,
const char *from_charset, size_t from_charset_len, int persistent)
{
- if (NULL == (self->to_charset = pemalloc(to_charset_len + 1, persistent))) {
- return PHP_ICONV_ERR_ALLOC;
- }
+ self->to_charset = pemalloc(to_charset_len + 1, persistent);
self->to_charset_len = to_charset_len;
- if (NULL == (self->from_charset = pemalloc(from_charset_len + 1, persistent))) {
- pefree(self->to_charset, persistent);
- return PHP_ICONV_ERR_ALLOC;
- }
+ self->from_charset = pemalloc(from_charset_len + 1, persistent);
self->from_charset_len = from_charset_len;
memcpy(self->to_charset, to_charset, to_charset_len);
}
out_buf_size = ocnt = prev_ocnt = initial_out_buf_size;
- if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
- return FAILURE;
- }
+ out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
php_stream_bucket_append(buckets_out, new_bucket);
out_buf_size = ocnt = initial_out_buf_size;
- if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
- return FAILURE;
- }
+ out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
} else {
- if (NULL == (new_out_buf = perealloc(out_buf, new_out_buf_size, persistent))) {
- if (NULL == (new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, persistent))) {
- goto out_failure;
- }
-
- php_stream_bucket_append(buckets_out, new_bucket);
- return FAILURE;
- }
+ new_out_buf = perealloc(out_buf, new_out_buf_size, persistent);
pd = new_out_buf + (pd - out_buf);
ocnt += (new_out_buf_size - out_buf_size);
out_buf = new_out_buf;
return NULL;
}
- if (NULL == (inst = pemalloc(sizeof(php_iconv_stream_filter), persistent))) {
- return NULL;
- }
+ inst = pemalloc(sizeof(php_iconv_stream_filter), persistent);
if (php_iconv_stream_filter_ctor(inst, to_charset, to_charset_len, from_charset, from_charset_len, persistent) != PHP_ICONV_ERR_SUCCESS) {
pefree(inst, persistent);
size = n + MBSTRG(default_detect_order_list_size);
/* make list */
list = (const mbfl_encoding **)pecalloc(size, sizeof(mbfl_encoding*), persistent);
- if (list != NULL) {
- entry = list;
- n = 0;
- bauto = 0;
- p1 = tmpstr;
- do {
- p2 = p = (char*)php_memnstr(p1, ",", 1, endp);
- if (p == NULL) {
- p = endp;
- }
+ entry = list;
+ n = 0;
+ bauto = 0;
+ p1 = tmpstr;
+ do {
+ p2 = p = (char*)php_memnstr(p1, ",", 1, endp);
+ if (p == NULL) {
+ p = endp;
+ }
+ *p = '\0';
+ /* trim spaces */
+ while (p1 < p && (*p1 == ' ' || *p1 == '\t')) {
+ p1++;
+ }
+ p--;
+ while (p > p1 && (*p == ' ' || *p == '\t')) {
*p = '\0';
- /* trim spaces */
- while (p1 < p && (*p1 == ' ' || *p1 == '\t')) {
- p1++;
- }
p--;
- while (p > p1 && (*p == ' ' || *p == '\t')) {
- *p = '\0';
- p--;
- }
- /* convert to the encoding number and check encoding */
- if (strcasecmp(p1, "auto") == 0) {
- if (!bauto) {
- const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
- const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
- size_t i;
- bauto = 1;
- for (i = 0; i < identify_list_size; i++) {
- *entry++ = mbfl_no2encoding(*src++);
- n++;
- }
- }
- } else {
- const mbfl_encoding *encoding = mbfl_name2encoding(p1);
- if (encoding) {
- *entry++ = encoding;
+ }
+ /* convert to the encoding number and check encoding */
+ if (strcasecmp(p1, "auto") == 0) {
+ if (!bauto) {
+ const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
+ const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
+ size_t i;
+ bauto = 1;
+ for (i = 0; i < identify_list_size; i++) {
+ *entry++ = mbfl_no2encoding(*src++);
n++;
- } else {
- ret = 0;
}
}
- p1 = p2 + 1;
- } while (n < size && p2 != NULL);
- if (n > 0) {
- if (return_list) {
- *return_list = list;
+ } else {
+ const mbfl_encoding *encoding = mbfl_name2encoding(p1);
+ if (encoding) {
+ *entry++ = encoding;
+ n++;
} else {
- pefree(list, persistent);
+ ret = 0;
}
+ }
+ p1 = p2 + 1;
+ } while (n < size && p2 != NULL);
+ if (n > 0) {
+ if (return_list) {
+ *return_list = list;
} else {
pefree(list, persistent);
- if (return_list) {
- *return_list = NULL;
- }
- ret = 0;
- }
- if (return_size) {
- *return_size = n;
}
} else {
+ pefree(list, persistent);
if (return_list) {
*return_list = NULL;
}
- if (return_size) {
- *return_size = 0;
- }
ret = 0;
}
+ if (return_size) {
+ *return_size = n;
+ }
efree(tmpstr);
}
i = zend_hash_num_elements(target_hash);
size = i + MBSTRG(default_detect_order_list_size);
list = (const mbfl_encoding **)pecalloc(size, sizeof(mbfl_encoding*), persistent);
- if (list != NULL) {
- entry = list;
- bauto = 0;
- n = 0;
- ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
- convert_to_string_ex(hash_entry);
- if (strcasecmp(Z_STRVAL_P(hash_entry), "auto") == 0) {
- if (!bauto) {
- const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
- const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
- size_t j;
-
- bauto = 1;
- for (j = 0; j < identify_list_size; j++) {
- *entry++ = mbfl_no2encoding(*src++);
- n++;
- }
- }
- } else {
- const mbfl_encoding *encoding = mbfl_name2encoding(Z_STRVAL_P(hash_entry));
- if (encoding) {
- *entry++ = encoding;
+ entry = list;
+ bauto = 0;
+ n = 0;
+ ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) {
+ convert_to_string_ex(hash_entry);
+ if (strcasecmp(Z_STRVAL_P(hash_entry), "auto") == 0) {
+ if (!bauto) {
+ const enum mbfl_no_encoding *src = MBSTRG(default_detect_order_list);
+ const size_t identify_list_size = MBSTRG(default_detect_order_list_size);
+ size_t j;
+
+ bauto = 1;
+ for (j = 0; j < identify_list_size; j++) {
+ *entry++ = mbfl_no2encoding(*src++);
n++;
- } else {
- ret = FAILURE;
}
}
- i--;
- } ZEND_HASH_FOREACH_END();
- if (n > 0) {
- if (return_list) {
- *return_list = list;
+ } else {
+ const mbfl_encoding *encoding = mbfl_name2encoding(Z_STRVAL_P(hash_entry));
+ if (encoding) {
+ *entry++ = encoding;
+ n++;
} else {
- pefree(list, persistent);
+ ret = FAILURE;
}
+ }
+ i--;
+ } ZEND_HASH_FOREACH_END();
+ if (n > 0) {
+ if (return_list) {
+ *return_list = list;
} else {
pefree(list, persistent);
- if (return_list) {
- *return_list = NULL;
- }
- ret = FAILURE;
- }
- if (return_size) {
- *return_size = n;
}
} else {
+ pefree(list, persistent);
if (return_list) {
*return_list = NULL;
}
- if (return_size) {
- *return_size = 0;
- }
ret = FAILURE;
}
+ if (return_size) {
+ *return_size = n;
+ }
}
return ret;
mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const zend_bool persistent)
{
*stats = pecalloc(1, sizeof(MYSQLND_STATS), persistent);
- if (*stats == NULL) {
- return;
- }
(*stats)->values = pecalloc(statistic_count, sizeof(uint64_t), persistent);
(*stats)->triggers = pecalloc(statistic_count, sizeof(mysqlnd_stat_trigger), persistent);
(*stats)->in_trigger = FALSE;
dbuf = (char *)emalloc(val_len + 1);
}
- if (!dbuf) {
- php_error_docref(NULL, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
- buf = &(sbuf[0]);
- buflen = sizeof(sbuf) - 1;
- break;
- }
-
buf = dbuf;
buflen = val_len;
}
if((valueretrieval & SNMP_VALUE_PLAIN) && val_len > buflen){
- if ((dbuf = (char *)emalloc(val_len + 1))) {
- buf = dbuf;
- buflen = val_len;
- } else {
- php_error_docref(NULL, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
- }
+ dbuf = (char *)emalloc(val_len + 1);
+ buf = dbuf;
+ buflen = val_len;
}
if (valueretrieval & SNMP_VALUE_PLAIN) {
objid_query->array_output = ((st & SNMP_CMD_WALK) ? TRUE : FALSE);
if (Z_TYPE_P(oid) == IS_STRING) {
objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
- if (objid_query->vars == NULL) {
- php_error_docref(NULL, E_WARNING, "emalloc() failed while parsing oid: %s", strerror(errno));
- efree(objid_query->vars);
- return FALSE;
- }
objid_query->vars[objid_query->count].oid = Z_STRVAL_P(oid);
if (st & SNMP_CMD_SET) {
if (Z_TYPE_P(type) == IS_STRING && Z_TYPE_P(value) == IS_STRING) {
return FALSE;
}
objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(Z_ARRVAL_P(oid)), 0);
- if (objid_query->vars == NULL) {
- php_error_docref(NULL, E_WARNING, "emalloc() failed while parsing oid array: %s", strerror(errno));
- efree(objid_query->vars);
- return FALSE;
- }
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(oid), tmp_oid) {
convert_to_string_ex(tmp_oid);
*session_p = (php_snmp_session *)emalloc(sizeof(php_snmp_session));
session = *session_p;
- if (session == NULL) {
- php_error_docref(NULL, E_WARNING, "emalloc() failed allocating session");
- return (-1);
- }
memset(session, 0, sizeof(php_snmp_session));
snmp_sess_init(session);
session->remote_port = SNMP_PORT;
session->peername = emalloc(MAX_NAME_LEN);
- if (session->peername == NULL) {
- php_error_docref(NULL, E_WARNING, "emalloc() failed while copying hostname");
- return (-1);
- }
/* we copy original hostname for further processing */
strlcpy(session->peername, hostname, MAX_NAME_LEN);
host_ptr = session->peername;
size_t ebuf_len = 32, eout_len = 0;
u_char *ebuf = (u_char *) emalloc(ebuf_len);
- if (ebuf == NULL) {
- php_error_docref(NULL, E_WARNING, "malloc failure setting contextEngineID");
- return (-1);
- }
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, contextEngineID)) {
php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", contextEngineID);
efree(ebuf);
fh.type = ZEND_HANDLE_FP;
browdata->htab = pemalloc(sizeof *browdata->htab, persistent);
- if (browdata->htab == NULL) {
- return FAILURE;
- }
-
zend_hash_init_ex(browdata->htab, 0, NULL,
persistent ? browscap_entry_dtor_persistent : browscap_entry_dtor, persistent, 0);
static int php_strip_tags_filter_ctor(php_strip_tags_filter *inst, const char *allowed_tags, size_t allowed_tags_len, int persistent)
{
if (allowed_tags != NULL) {
- if (NULL == (inst->allowed_tags = pemalloc(allowed_tags_len, persistent))) {
- return FAILURE;
- }
+ inst->allowed_tags = pemalloc(allowed_tags_len, persistent);
memcpy((char *)inst->allowed_tags, allowed_tags, allowed_tags_len);
inst->allowed_tags_len = (int)allowed_tags_len;
} else {
inst = pemalloc(sizeof(php_strip_tags_filter), persistent);
- if (inst == NULL) { /* it's possible pemalloc returns NULL
- instead of causing it to bail out */
- return NULL;
- }
-
if (filterparams != NULL) {
if (Z_TYPE_P(filterparams) == IS_ARRAY) {
zval *tmp;
if ((tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1)) != NULL) {
zend_string *str = zval_get_string(tmpval);
- if (NULL == (*pretval = pemalloc(ZSTR_LEN(str) + 1, persistent))) {
- return PHP_CONV_ERR_ALLOC;
- }
-
+ *pretval = pemalloc(ZSTR_LEN(str) + 1, persistent);
*pretval_len = ZSTR_LEN(str);
memcpy(*pretval, ZSTR_VAL(str), ZSTR_LEN(str) + 1);
zend_string_release(str);
}
out_buf_size = ocnt = initial_out_buf_size;
- if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
- return FAILURE;
- }
+ out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
php_stream_bucket_append(buckets_out, new_bucket);
out_buf_size = ocnt = initial_out_buf_size;
- if (NULL == (out_buf = pemalloc(out_buf_size, persistent))) {
- return FAILURE;
- }
+ out_buf = pemalloc(out_buf_size, persistent);
pd = out_buf;
} else {
- if (NULL == (new_out_buf = perealloc(out_buf, new_out_buf_size, persistent))) {
- if (NULL == (new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, persistent))) {
- goto out_failure;
- }
-
- php_stream_bucket_append(buckets_out, new_bucket);
- return FAILURE;
- }
+ new_out_buf = perealloc(out_buf, new_out_buf_size, persistent);
pd = new_out_buf + (pd - out_buf);
ocnt += (new_out_buf_size - out_buf_size);
out_buf = new_out_buf;
*buf = NULL;
if (cc >= 0) {
- if ((*buf = emalloc(++cc)) != NULL) {
- if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) {
- efree(*buf);
- *buf = NULL;
- }
+ *buf = emalloc(++cc);
+ if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) {
+ efree(*buf);
+ *buf = NULL;
}
}
because the content is in *error_message now */
#define SMTP_ERROR_RESPONSE(response) { \
if (response && error_message) { \
- if (NULL != (*error_message = ecalloc(1, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response)))) { \
- snprintf(*error_message, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response), SMTP_ERROR_RESPONSE_SPEC, response); \
- } \
+ *error_message = ecalloc(1, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response)); \
+ snprintf(*error_message, sizeof(SMTP_ERROR_RESPONSE_SPEC) + strlen(response), SMTP_ERROR_RESPONSE_SPEC, response); \
efree(response); \
} \
}
zend_string_free(headers_lc);
}
/* 128 is safe here, the specifier in snprintf isn't longer than that */
- if (NULL == (*error_message = ecalloc(1, HOST_NAME_LEN + 128))) {
- return FAILURE;
- }
+ *error_message = ecalloc(1, HOST_NAME_LEN + 128);
snprintf(*error_message, HOST_NAME_LEN + 128,
"Failed to connect to mailserver at \"%s\" port %d, verify your \"SMTP\" "
"and \"smtp_port\" setting in php.ini or use ini_set()",
/* Now that we've identified that we've a Bcc list,
remove it from the current header. */
- if (NULL == (stripped_header = ecalloc(1, strlen(headers)))) {
- return OUT_OF_MEMORY;
- }
+ stripped_header = ecalloc(1, strlen(headers));
/* headers = point to string start of header
pos1 = pointer IN headers where the Bcc starts
'4' = Length of the characters 'bcc:'
/* Simplify the code that we create a copy of stripped_header no matter if
we actually strip something or not. So we've a single efree() later. */
if (headers && !stripped_header) {
- if (NULL == (stripped_header = estrndup(headers, strlen(headers)))) {
- return OUT_OF_MEMORY;
- }
+ stripped_header = estrndup(headers, strlen(headers));
}
if ((res = Post("DATA\r\n")) != SUCCESS) {
static int addToHeader(char **header_buffer, const char *specifier, char *string)
{
- if (NULL == (*header_buffer = erealloc(*header_buffer, strlen(*header_buffer) + strlen(specifier) + strlen(string) + 1))) {
- return 0;
- }
+ *header_buffer = erealloc(*header_buffer, strlen(*header_buffer) + strlen(specifier) + strlen(string) + 1);
sprintf(*header_buffer + strlen(*header_buffer), specifier, string);
return 1;
}
size_t i;
if (xheaders) {
- if (NULL == (headers_lc = estrdup(xheaders))) {
- return OUT_OF_MEMORY;
- }
+ headers_lc = estrdup(xheaders);
for (i = 0; i < strlen(headers_lc); i++) {
headers_lc[i] = tolower(headers_lc[i]);
}