void VariableSerializer::write(double v) { switch (m_type) { case JSON: if (!isinf(v) && !isnan(v)) { char *buf; if (v == 0.0) v = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*k", 14, v); *m_out << buf; free(buf); } else { // PHP issues a warning: double INF/NAN does not conform to the // JSON spec, encoded as 0. *m_out << '0'; } break; case VarExport: case PrintR: { char *buf; if (v == 0.0) v = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, v); *m_out << buf; free(buf); } break; case VarDump: case DebugDump: { char *buf; if (v == 0.0) v = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "float(%.*G)", 14, v); indent(); *m_out << buf; free(buf); writeRefCount(); *m_out << '\n'; } break; case Serialize: *m_out << "d:"; if (isnan(v)) { *m_out << "NAN"; } else if (isinf(v)) { *m_out << "INF"; } else { char *buf; if (v == 0.0) v = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, v); *m_out << buf; free(buf); } *m_out << ';'; break; default: ASSERT(false); break; } checkOutputSize(); }
/* {{{ void apm_error(int type, const char *format, ...) This function provides a hook for error */ void apm_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) { TSRMLS_FETCH(); char *msg; va_list args_copy; zend_module_entry tmp_mod_entry; /* A copy of args is needed to be used for the old_error_cb */ va_copy(args_copy, args); vspprintf(&msg, 0, format, args_copy); va_end(args_copy); if (APM_G(event_enabled)) { /* We need to see if we have an uncaught exception fatal error now */ if (type == E_ERROR && strncmp(msg, "Uncaught exception", 18) == 0) { } else { insert_event(type, (char *) error_filename, error_lineno, msg TSRMLS_CC); } } efree(msg); /* Calling saved callback function for error handling, unless xdebug is loaded */ if (zend_hash_find(&module_registry, "xdebug", 7, (void**) &tmp_mod_entry) != SUCCESS) { old_error_cb(type, error_filename, error_lineno, format, args); } }
int vld_printf(FILE *stream, const char* fmt, ...) { char *message; int len; va_list args; int i = 0, j = 0; char *ptr; const char EOL='\n'; TSRMLS_FETCH(); va_start(args, fmt); len = vspprintf(&message, 0, fmt, args); va_end(args); if (VLD_G(format)) { ptr = message; while (j < strlen(ptr)) { if (!isspace(ptr[j]) || ptr[j] == EOL) { ptr[i++] = ptr[j]; } j++; } ptr[i] = 0; fprintf(stream, "%s%s", VLD_G(col_sep), ptr); } else { fprintf(stream, "%s", message); } efree(message); return len; }
PHPAPI int spprintf(char **pbuf, size_t max_len, const char *format, ...) { va_list ap; va_start(ap, format); int cc = vspprintf(pbuf, max_len, format, ap); va_end(ap); return cc; }
static void php_yar_client_trigger_error(int throw_exception TSRMLS_DC, int code, const char *format, ...) { /* {{{ */ va_list arg; char *message; zend_class_entry *ce; va_start(arg, format); vspprintf(&message, 0, format, arg); va_end(arg); if (throw_exception) { switch (code) { case YAR_ERR_PACKAGER: ce = yar_client_packager_exception_ce; break; case YAR_ERR_PROTOCOL: ce = yar_client_protocol_exception_ce; break; case YAR_ERR_TRANSPORT: ce = yar_client_transport_exception_ce; break; case YAR_ERR_REQUEST: case YAR_ERR_EXCEPTION: ce = yar_server_exception_ce; break; default: ce = yar_client_exception_ce; break; } zend_throw_exception(ce, message, code TSRMLS_CC); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%d] %s", code, message); } efree(message); } /* }}} */
StringData* buildStringData(double n) { char *buf; if (n == 0.0) n = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, n); return NEW(StringData)(buf, AttachString); }
void syslog(int priority, const char *message, ...) { va_list args; LPTSTR strs[2]; unsigned short etype; char *tmp = NULL; DWORD evid; /* default event source */ if (INVALID_HANDLE_VALUE == PW32G(log_source)) openlog("php", LOG_PID, LOG_SYSLOG); switch (priority) { /* translate UNIX type into NT type */ case LOG_ALERT: etype = EVENTLOG_ERROR_TYPE; evid = PHP_SYSLOG_ERROR_TYPE; break; case LOG_INFO: etype = EVENTLOG_INFORMATION_TYPE; evid = PHP_SYSLOG_INFO_TYPE; break; default: etype = EVENTLOG_WARNING_TYPE; evid = PHP_SYSLOG_WARNING_TYPE; } va_start(args, message); /* initialize vararg mechanism */ vspprintf(&tmp, 0, message, args); /* build message */ strs[0] = PW32G(log_header); /* write header */ strs[1] = tmp; /* then the message */ /* report the event */ ReportEvent(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strs, NULL); va_end(args); efree(tmp); }
String::String(double n) { char *buf; if (n == 0.0) n = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, n); m_px = NEW(StringData)(buf, AttachString); m_px->incRefCount(); }
StringData* buildStringData(double n) { char *buf; TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE); if (n == 0.0) n = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, n); return NEW(StringData)(buf, AttachString); }
/** * Applies sprintf function to a variable list */ int phalcon_spprintf(char **message, int max_len, char *format, ...){ va_list arg; int len; va_start(arg, format); len = vspprintf(message, max_len, format, arg); va_end(arg); return len; }
String::String(double n) { char *buf; TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE); if (n == 0.0) n = 0.0; // so to avoid "-0" output vspprintf(&buf, 0, "%.*G", 14, n); m_px = NEW(StringData)(buf, AttachString); m_px->setRefCount(1); }
/* {{{ gdCtxPrintf */ void gdCtxPrintf(gdIOCtx * out, const char *format, ...) { char *buf; int len; va_list args; va_start(args, format); len = vspprintf(&buf, 0, format, args); va_end(args); out->putBuf(out, buf, len); efree(buf); }
void php_yar_error_ex(yar_response_t *response, int type TSRMLS_DC, const char *format, va_list args) /* {{{ */ { char *msg; uint len; len = vspprintf(&msg, 0, format, args); php_yar_response_set_error(response, type, msg, len TSRMLS_CC); /* intentionally missed efree(msg); */ return; } /* }}} */
zend_object * pion_exception_new_ex(zend_class_entry * exception_ce, long code, const char * format, ...) { va_list arg; char *message; zend_object * exception; va_start(arg, format); vspprintf(&message, 0, format, arg); va_end(arg); exception = pion_exception_new(exception_ce, message, code); efree(message); return exception; }
static void error (const char *format,...) { va_list args; char *tmp; TSRMLS_FETCH(); va_start(args, format); vspprintf(&tmp, 0, format, args); va_end(args); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s: %s", LIBNAME, tmp); efree(tmp); }
int _record_error_formatted(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line, const char *sql_state, int error_code, const char *format, ...) { va_list arg; char *error_message; int ret = 1; va_start(arg, format); vspprintf(&error_message, 0, format, arg); va_end(arg); ret = _record_error(dbh, stmt, file, line, sql_state, error_code, strdup(error_message)); efree((char *)error_message); return ret; }
static void qb_append_string(zval *string, const char *format, ...) { uint32_t current_len = Z_STRLEN_P(string), len; char *addition; va_list args; va_start(args, format); len = vspprintf(&addition, 0, format, args); va_end(args); Z_STRVAL_P(string) = erealloc(Z_STRVAL_P(string), current_len + len + 1); Z_STRLEN_P(string) = current_len + len; memcpy(Z_STRVAL_P(string) + current_len, addition, len + 1); efree(addition); }
static int php_info_printf(const char *fmt, ...) /* {{{ */ { char *buf; size_t len, written; va_list argv; va_start(argv, fmt); len = vspprintf(&buf, 0, fmt, argv); va_end(argv); written = php_output_write(buf, len); efree(buf); return written; }
static int php_info_printf(const char *fmt, ...) /* {{{ */ { char *buf; int len, written; va_list argv; TSRMLS_FETCH(); va_start(argv, fmt); len = vspprintf(&buf, 0, fmt, argv); va_end(argv); written = php_output_write_utf8(buf, len TSRMLS_CC); efree(buf); return written; }
zend_object *throw_exce(php_pqexc_type_t type, const char *fmt, ...) { char *msg; zend_object *zexc; va_list argv; va_start(argv, fmt); vspprintf(&msg, 0, fmt, argv); va_end(argv); zexc = zend_throw_exception(exce(type), msg, type); efree(msg); return zexc; }
/* {{{ void http_error(long, long, char*) */ void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...) { va_list args; va_start(args, format); #ifdef ZEND_ENGINE_2 if ((type == E_THROW) || (GLOBAL_ERROR_HANDLING == EH_THROW)) { char *message; zend_class_entry *ce = http_exception_get_for_code(code); http_try { vspprintf(&message, 0, format, args); zend_throw_exception(ce, message, code TSRMLS_CC); efree(message); } http_catch(GLOBAL_EXCEPTION_CLASS ? GLOBAL_EXCEPTION_CLASS : HTTP_EX_DEF_CE); } else
int diff_printf(const char *format, ...) { va_list args; int ret; char *buffer; int size; TSRMLS_FETCH(); va_start(args, format); size = vspprintf(&buffer, 0, format, args); ret = PHPWRITE(buffer, size); efree(buffer); va_end(args); return ret; }
static void throttle_debug(const char *format, ...) { char *buf = NULL; va_list ap; TSRMLS_FETCH(); if (!THROTTLE_G(debug)) { return; } va_start(ap, format); vspprintf(&buf, 0, format, ap); va_end(ap); sapi_module.log_message(buf TSRMLS_CC); efree(buf); }
/** {{{void yaf_trigger_error(int type TSRMLS_DC, char *format, ...) */ void yaf_trigger_error(int type TSRMLS_DC, char *format, ...) { va_list args; char *message; uint msg_len; va_start(args, format); msg_len = vspprintf(&message, 0, format, args); va_end(args); if (YAF_G(throw_exception)) { yaf_throw_exception(type, message TSRMLS_CC); } else { yaf_application_t *app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC); zend_update_property_long(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), type TSRMLS_CC); zend_update_property_stringl(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), message, msg_len TSRMLS_CC); php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, message); } efree(message); }
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...) { zval *sql_ex; va_list arg; char *message; va_start(arg, format); vspprintf(&message, 0, format, arg); va_end(arg);; #if WANT_EXCEPTIONS if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) #endif { php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message); efree(message); return; } #if WANT_EXCEPTIONS MAKE_STD_ZVAL(sql_ex); object_init_ex(sql_ex, mysqli_exception_class_entry); if (message) { zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1, message TSRMLS_CC); } if (sqlstate) { zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1, sqlstate TSRMLS_CC); } else { zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1, "00000" TSRMLS_CC); } efree(message); zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC); zend_throw_exception_object(sql_ex TSRMLS_CC); #endif }
/** {{{ ze_error */ PHP_ZOEEY_API void ze_error(int type TSRMLS_DC, const char * name, ... ) { va_list ap ; int len = 0; char * buf = NULL; char * msg = NULL; if (EG(exception)) { zend_throw_exception_object(EG(exception) TSRMLS_CC); return; } va_start(ap, name); len = vspprintf(&buf, 0, name, ap); va_end(ap); spprintf(&msg, 0, INI_STR("errors_doc_url"), buf); php_error(type, msg); efree(msg); efree(buf); }
/*{{{LICENSE +-----------------------------------------------------------------------+ | slightphp Framework | +-----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of the GNU General Public License as published by | | the Free Software Foundation. You should have received a copy of the | | GNU General Public License along with this program. If not, see | | http://www.gnu.org/licenses/. | | Copyright (C) 2008-2009. All Rights Reserved. | +-----------------------------------------------------------------------+ | Supports: http://www.slightphp.com | +-----------------------------------------------------------------------+ }}}*/ int debug(char*format,...){ TSRMLS_FETCH(); zval *_debug_flag = zend_read_static_property(slightphp_ce_ptr,"_debug",sizeof("_debug")-1,1 ); convert_to_long(_debug_flag); if(Z_LVAL_P(_debug_flag)) { va_list args; char *buffer; int size; TSRMLS_FETCH(); va_start(args, format); size = vspprintf(&buffer, 0, format, args); _php_error_log(0,buffer,NULL,NULL ); zend_printf("<!--slightphp debug:%s-->",buffer); efree(buffer); va_end(args); } zval_dtor(_debug_flag); }
/* ERRORS */ static void do_from_to_zval_err(struct err_s *err, zend_llist *keys, const char *what_conv, const char *fmt, va_list ap) { smart_str path = {0}; const char **node; char *user_msg; int user_msg_size; zend_llist_position pos; if (err->has_error) { return; } for (node = zend_llist_get_first_ex(keys, &pos); node != NULL; node = zend_llist_get_next_ex(keys, &pos)) { smart_str_appends(&path, *node); smart_str_appends(&path, " > "); } if (path.s && path.s->len > 3) { path.s->len -= 3; } smart_str_0(&path); user_msg_size = vspprintf(&user_msg, 0, fmt, ap); err->has_error = 1; err->level = E_WARNING; spprintf(&err->msg, 0, "error converting %s data (path: %s): %.*s", what_conv, path.s && *path.s->val != '\0' ? path.s->val : "unavailable", user_msg_size, user_msg); err->should_free = 1; efree(user_msg); smart_str_free(&path); }
/* {{{ void apm_error(int type, const char *format, ...) This function provides a hook for error */ void apm_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) { char *msg; va_list args_copy; zend_module_entry tmp_mod_entry; TSRMLS_FETCH(); /* A copy of args is needed to be used for the old_error_cb */ va_copy(args_copy, args); vspprintf(&msg, 0, format, args_copy); va_end(args_copy); if (APM_G(event_enabled)) { process_event(APM_EVENT_ERROR, type, (char *) error_filename, error_lineno, msg TSRMLS_CC); } efree(msg); /* Calling saved callback function for error handling, unless xdebug is loaded */ if (zend_hash_find(&module_registry, "xdebug", 7, (void**) &tmp_mod_entry) != SUCCESS) { old_error_cb(type, error_filename, error_lineno, format, args); } }
/** * Throws an exception with a string format as parameter */ void zephir_throw_exception_format(zend_class_entry *ce, const char *format, ...) { zval object, msg; int ZEPHIR_LAST_CALL_STATUS = 0, len; char *buffer; va_list args; object_init_ex(&object, ce); va_start(args, format); len = vspprintf(&buffer, 0, format, args); va_end(args); ZVAL_STRINGL(&msg, buffer, len); efree(buffer); ZEPHIR_CALL_METHOD(NULL, &object, "__construct", NULL, 0, &msg); if (ZEPHIR_LAST_CALL_STATUS != FAILURE) { zend_throw_exception_object(&object); } zval_ptr_dtor(&msg); }