Skip to content

Commit ceabdbb

Browse files
author
Scott MacVicar
committed
MFH Add asprintf, use regular system malloc and free and add checks in configure.in for the functions
1 parent 7d4fd3f commit ceabdbb

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

configure.in

+2
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ usleep \
637637
nanosleep \
638638
utime \
639639
vsnprintf \
640+
vasprintf \
641+
asprintf \
640642
)
641643

642644
dnl Check for getaddrinfo, should be a better way, but...

ext/fileinfo/libmagic/print.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...)
6262

6363
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Warning: %s", expanded_format);
6464

65-
efree(expanded_format);
65+
free(expanded_format);
6666
}
6767

6868
protected const char *

main/snprintf.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -1280,9 +1280,9 @@ PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ *
12801280
*buf = NULL;
12811281

12821282
if (cc >= 0) {
1283-
if ((*buf = emalloc(++cc)) != NULL) {
1283+
if ((*buf = malloc(++cc)) != NULL) {
12841284
if ((cc = ap_php_vsnprintf(*buf, cc, format, ap)) < 0) {
1285-
efree(*buf);
1285+
free(*buf);
12861286
*buf = NULL;
12871287
}
12881288
}
@@ -1292,6 +1292,18 @@ PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ *
12921292
}
12931293
/* }}} */
12941294

1295+
PHPAPI int ap_php_asprintf(char **buf, const char *format, ...) /* {{{ */
1296+
{
1297+
int cc;
1298+
va_list ap;
1299+
1300+
va_start(ap, format);
1301+
cc = vasprintf(buf, format, ap);
1302+
va_end(ap);
1303+
return cc;
1304+
}
1305+
/* }}} */
1306+
12951307
/*
12961308
* Local variables:
12971309
* tab-width: 4

main/snprintf.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list a
8383
PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...);
8484
PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap);
8585
PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap);
86+
PHPAPI int ap_php_asprintf(char **buf, const char *format, ...);
8687
PHPAPI int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
8788
PHPAPI char * php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf);
8889
PHPAPI char * php_conv_fp(register char format, register double num,
@@ -110,10 +111,13 @@ END_EXTERN_C()
110111
#endif
111112
#define vsnprintf ap_php_vsnprintf
112113

113-
#ifdef vasprintf
114-
#undef vasprintf
115-
#endif
114+
#ifndef HAVE_VASPRINTF
116115
#define vasprintf ap_php_vasprintf
116+
#endif
117+
118+
#ifndef HAVE_ASPRINTF
119+
#define asprintf ap_php_asprintf
120+
#endif
117121

118122
#ifdef sprintf
119123
#undef sprintf

0 commit comments

Comments
 (0)