80#define SCAN_NOSKIP 0x1
81#define SCAN_SUPPRESS 0x2
82#define SCAN_UNSIGNED 0x4
85#define SCAN_SIGNOK 0x10
86#define SCAN_NODIGITS 0x20
87#define SCAN_NOZERO 0x40
89#define SCAN_PTOK 0x100
90#define SCAN_EXPOK 0x200
92#define UCHAR(x) (zend_uchar)(x)
114static char *BuildCharSet(
CharSet *cset,
char *format);
115static int CharInSet(
CharSet *cset,
int ch);
116static void ReleaseCharSet(
CharSet *cset);
137static char * BuildCharSet(
CharSet *cset,
char *format)
179 if (*
ch ==
']' || *
ch ==
'-') {
184 if (*format ==
'-') {
190 }
else if (*
ch ==
'-') {
196 if (*format ==
']') {
238static int CharInSet(
CharSet *cset,
int c)
243 for (i = 0; i < cset->
nchars; i++) {
250 for (i = 0; i < cset->
nranges; i++) {
277static void ReleaseCharSet(
CharSet *cset)
309#define STATIC_LIST_SIZE 16
313 int *nassign = staticAssign;
321 if (numVars > nspace) {
325 for (i = 0; i < nspace; i++) {
329 xpgSize = objIndex = gotXpg = gotSequential = 0;
331 while (*format !=
'\0') {
348 if ( isdigit( (
int)*
ch ) ) {
364 if ((
value < 1) || (numVars && (
value > numVars))) {
366 }
else if (numVars == 0) {
382 xpgSize = (xpgSize >
value) ? xpgSize :
value;
384 objIndex =
value - 1;
392 zend_value_error(
"%s",
"cannot mix \"%\" and \"%n$\" conversion specifiers");
409 if ((*
ch ==
'l') || (*
ch ==
'L') || (*
ch ==
'h')) {
450 if (*format ==
'\0') {
455 if (*format ==
'\0') {
461 if (*format ==
'\0') {
467 if (*format ==
'\0') {
484 if (objIndex >= nspace) {
496 if (nassign == staticAssign) {
499 nassign[i] = staticAssign[i];
502 nassign = (
void *)
erealloc((
void *)nassign, nspace *
sizeof(
int));
504 for (i =
value; i < nspace; i++) {
524 *totalSubs = numVars;
526 for (i = 0; i < numVars; i++) {
527 if (nassign[i] > 1) {
528 zend_value_error(
"%s",
"Variable is assigned by multiple \"%n$\" conversion specifiers");
530 }
else if (!xpgSize && (nassign[i] == 0)) {
540 if (nassign != staticAssign) {
541 efree((
char *)nassign);
549 zend_value_error(
"Different numbers of variable names and field specifiers");
553 if (nassign != staticAssign) {
554 efree((
char *)nassign);
557#undef STATIC_LIST_SIZE
578 int numVars, nconversions, totalVars = -1;
582 char *
end, *baseString;
595 if ((varStart > argCount) || (varStart < 0)){
598 numVars = argCount - varStart;
611 objIndex = numVars ? varStart : 0;
617 for (i = varStart;i < argCount;i++){
632 for (i = 0; i < totalVars; i++) {
652 while (*format !=
'\0') {
659 if ( isspace( (
int)*
ch ) ) {
661 while ( isspace( (
int)sch ) ) {
662 if (*
string ==
'\0') {
673 if (*
string ==
'\0') {
697 }
else if ( isdigit(
UCHAR(*
ch))) {
702 objIndex = varStart +
value - 1;
719 if ((*
ch ==
'l') || (*
ch ==
'L') || (*
ch ==
'h')) {
729 if (numVars && objIndex >= argCount) {
731 }
else if (numVars) {
800 if (*
string ==
'\0') {
810 while (*
string !=
'\0') {
812 if (! isspace((
int)sch) ) {
817 if (*
string ==
'\0') {
836 while (*
end !=
'\0') {
838 if ( isspace( (
int)sch ) ) {
847 if (numVars && objIndex >= argCount) {
849 }
else if (numVars) {
867 format = BuildCharSet(&cset, format);
868 while (*
end !=
'\0') {
870 if (!CharInSet(&cset, (
int)sch)) {
878 ReleaseCharSet(&cset);
887 if (numVars && objIndex >= argCount) {
889 }
else if (numVars) {
926 if ((width == 0) || (width >
sizeof(
buf) - 1)) {
927 width =
sizeof(
buf) - 1;
931 for (
end =
buf; width > 0; width--) {
956 case '1':
case '2':
case '3':
case '4':
957 case '5':
case '6':
case '7':
974 case 'A':
case 'B':
case 'C':
975 case 'D':
case 'E':
case 'F':
976 case 'a':
case 'b':
case 'c':
977 case 'd':
case 'e':
case 'f':
1010 if (*
string ==
'\0') {
1020 if (*
string ==
'\0') {
1024 }
else if (
end[-1] ==
'x' ||
end[-1] ==
'X') {
1039 if (numVars && objIndex >= argCount) {
1041 }
else if (numVars) {
1049 if (numVars && objIndex >= argCount) {
1051 }
else if (numVars) {
1066 if ((width == 0) || (width >
sizeof(
buf) - 1)) {
1067 width =
sizeof(
buf) - 1;
1070 for (
end =
buf; width > 0; width--) {
1072 case '0':
case '1':
case '2':
case '3':
1073 case '4':
case '5':
case '6':
case '7':
1114 if (*
string ==
'\0') {
1129 if (*
string ==
'\0') {
1140 if (*
end !=
'e' && *
end !=
'E') {
1153 if (numVars && objIndex >= argCount) {
1155 }
else if (numVars) {
1170 if (underflow && (0==nconversions)) {
1173 }
else if (numVars) {
1176 }
else if (nconversions < totalVars) {
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
unsigned const char * end
PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
PHPAPI int php_sscanf_internal(char *string, char *format, int argCount, zval *args, int varStart, zval *return_value)
zend_long(* int_string_formater)(const char *, char **, int)
#define SCAN_ERROR_INVALID_FORMAT
file_private int match(struct magic_set *, struct magic *, size_t, const struct buffer *, size_t, int, int, int, uint16_t *, uint16_t *, int *, int *, int *, int *, int *)
struct CharSet::Range * ranges
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length)
ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str)
ZEND_API void add_index_double(zval *arg, zend_ulong index, double d)
ZEND_API void add_index_long(zval *arg, zend_ulong index, zend_long n)
#define ZEND_TRY_ASSIGN_REF_STRINGL(zv, string, len)
#define ZEND_TRY_ASSIGN_REF_LONG(zv, lval)
#define ZEND_TRY_ASSIGN_REF_DOUBLE(zv, dval)
#define ZEND_TRY_ASSIGN_REF_STRING(zv, string)
#define erealloc(ptr, size)
#define safe_emalloc(nmemb, size, offset)
#define ZEND_STRTOUL(s0, s1, base)
ZEND_API void ZEND_FASTCALL convert_to_null(zval *op)
ZEND_API double zend_strtod(const char *s00, const char **se)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)