Skip to content

Commit 91abad1

Browse files
committed
Better test coverage
1 parent 6e008d4 commit 91abad1

File tree

13 files changed

+140
-134
lines changed

13 files changed

+140
-134
lines changed

Zend/zend_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ static int zend_parse_arg(int arg_num, zval **arg, va_list *va, const char **spe
710710
const char *space;
711711
const char *class_name = get_active_class_name(&space TSRMLS_CC);
712712

713+
if (0 == strcmp(expected_type, "unknown")) {
714+
severity = E_ERROR;
715+
}
713716
if (error) {
714717
zend_error(severity, "%s%s%s() expects parameter %d %s",
715718
class_name, space, get_active_function_name(TSRMLS_C), arg_num, error);

Zend/zend_exceptions.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */
8686
#ifdef HAVE_DTRACE
8787
if (DTRACE_EXCEPTION_THROWN_ENABLED()) {
8888
char *classname;
89-
int name_len;
89+
zend_str_size name_len;
9090

9191
if (exception != NULL) {
9292
zend_get_object_classname(exception, &classname, &name_len TSRMLS_CC);
@@ -196,9 +196,10 @@ ZEND_METHOD(exception, __construct)
196196
char *message = NULL;
197197
long code = 0;
198198
zval *object, *previous = NULL;
199-
int argc = ZEND_NUM_ARGS(), message_len;
199+
int argc = ZEND_NUM_ARGS();
200+
zend_str_size message_len;
200201

201-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|slO!", &message, &message_len, &code, &previous, default_exception_ce) == FAILURE) {
202+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|SlO!", &message, &message_len, &code, &previous, default_exception_ce) == FAILURE) {
202203
zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])");
203204
}
204205

@@ -225,9 +226,10 @@ ZEND_METHOD(error_exception, __construct)
225226
char *message = NULL, *filename = NULL;
226227
long code = 0, severity = E_ERROR, lineno;
227228
zval *object, *previous = NULL;
228-
int argc = ZEND_NUM_ARGS(), message_len, filename_len;
229+
int argc = ZEND_NUM_ARGS();
230+
zend_str_size message_len, filename_len;
229231

230-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, default_exception_ce) == FAILURE) {
232+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|SllSlO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, default_exception_ce) == FAILURE) {
231233
zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])");
232234
}
233235

@@ -262,7 +264,7 @@ ZEND_METHOD(error_exception, __construct)
262264
return; \
263265
}
264266

265-
static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */
267+
static void _default_exception_get_entry(zval *object, char *name, zend_str_size_int name_len, zval *return_value TSRMLS_DC) /* {{{ */
266268
{
267269
zval *value;
268270

@@ -341,7 +343,7 @@ ZEND_METHOD(error_exception, getSeverity)
341343

342344
#define TRACE_APPEND_STRL(val, vallen) \
343345
{ \
344-
int l = vallen; \
346+
zend_str_size l = vallen; \
345347
*str = (char*)erealloc(*str, *len + l + 1); \
346348
memcpy((*str) + *len, val, l); \
347349
*len += l; \
@@ -365,10 +367,10 @@ ZEND_METHOD(error_exception, getSeverity)
365367
static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
366368
{
367369
char **str;
368-
int *len;
370+
zend_str_size *len;
369371

370372
str = va_arg(args, char**);
371-
len = va_arg(args, int*);
373+
len = va_arg(args, zend_str_size*);
372374

373375
/* the trivial way would be to do:
374376
* conver_to_string_ex(arg);
@@ -381,7 +383,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z
381383
TRACE_APPEND_STR("NULL, ");
382384
break;
383385
case IS_STRING: {
384-
int l_added;
386+
zend_str_size l_added;
385387
TRACE_APPEND_CHR('\'');
386388
if (Z_STRSIZE_PP(arg) > 15) {
387389
TRACE_APPEND_STRL(Z_STRVAL_PP(arg), 15);
@@ -413,15 +415,15 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z
413415
case IS_LONG: {
414416
long lval = Z_LVAL_PP(arg);
415417
char s_tmp[MAX_LENGTH_OF_LONG + 1];
416-
int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */
418+
zend_str_size l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */
417419
TRACE_APPEND_STRL(s_tmp, l_tmp);
418420
TRACE_APPEND_STR(", ");
419421
break;
420422
}
421423
case IS_DOUBLE: {
422424
double dval = Z_DVAL_PP(arg);
423425
char *s_tmp;
424-
int l_tmp;
426+
zend_str_size l_tmp;
425427

426428
s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
427429
l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval); /* SAFE */
@@ -436,7 +438,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z
436438
break;
437439
case IS_OBJECT: {
438440
const char *class_name;
439-
zend_uint class_name_len;
441+
zend_str_size class_name_len;
440442
int dup;
441443

442444
TRACE_APPEND_STR("Object(");
@@ -461,7 +463,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z
461463
static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
462464
{
463465
char *s_tmp, **str;
464-
int *len, *num;
466+
zend_str_size *len, *num;
465467
long line;
466468
HashTable *ht = Z_ARRVAL_PP(frame);
467469
zval **file, **tmp;
@@ -472,8 +474,8 @@ static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list arg
472474
}
473475

474476
str = va_arg(args, char**);
475-
len = va_arg(args, int*);
476-
num = va_arg(args, int*);
477+
len = va_arg(args, zend_str_size*);
478+
num = va_arg(args, zend_str_size*);
477479

478480
s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1);
479481
sprintf(s_tmp, "#%d ", (*num)++);
@@ -528,7 +530,7 @@ ZEND_METHOD(exception, getTraceAsString)
528530
{
529531
zval *trace;
530532
char *res, **str, *s_tmp;
531-
int res_len = 0, *len = &res_len, num = 0;
533+
zend_str_size res_len = 0, *len = &res_len, num = 0;
532534

533535
DEFAULT_0_PARAMS;
534536

@@ -560,10 +562,10 @@ ZEND_METHOD(exception, getPrevious)
560562
RETURN_ZVAL(previous, 1, 0);
561563
}
562564

563-
int zend_spprintf(char **message, int max_len, char *format, ...) /* {{{ */
565+
zend_str_size_int zend_spprintf(char **message, zend_str_size_int max_len, char *format, ...) /* {{{ */
564566
{
565567
va_list arg;
566-
int len;
568+
zend_str_size len;
567569

568570
va_start(arg, format);
569571
len = zend_vspprintf(message, max_len, format, arg);
@@ -578,7 +580,7 @@ ZEND_METHOD(exception, __toString)
578580
{
579581
zval message, file, line, *trace, *exception;
580582
char *str, *prev_str;
581-
int len = 0;
583+
zend_str_size len = 0;
582584
zend_fcall_info fci;
583585
zval fname;
584586

@@ -783,7 +785,7 @@ ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, char
783785
}
784786
/* }}} */
785787

786-
static void zend_error_va(int type, const char *file, uint lineno, const char *format, ...) /* {{{ */
788+
static void zend_error_va(int type, const char *file, zend_str_size_uint lineno, const char *format, ...) /* {{{ */
787789
{
788790
va_list args;
789791

Zend/zend_exceptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC);
5353
ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC);
5454

5555
/* do not export, in php it's available thru spprintf directly */
56-
int zend_spprintf(char **message, int max_len, char *format, ...);
56+
zend_str_size_int zend_spprintf(char **message, zend_str_size_int max_len, char *format, ...);
5757

5858
END_EXTERN_C()
5959

0 commit comments

Comments
 (0)