stdio: fix bypassed __scanf_end at end of scanf

This commit is contained in:
Lephenixnoir 2024-01-14 22:02:53 +01:00
parent 0cef8ca891
commit be4c2b8d33
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
7 changed files with 18 additions and 9 deletions

View file

@ -10,7 +10,9 @@ int fscanf(FILE * restrict fp, char const * restrict fmt, ...)
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
__scanf_start(&in);
int count = __scanf(&in, fmt, &args); int count = __scanf(&in, fmt, &args);
__scanf_end(&in);
va_end(args); va_end(args);
return count; return count;

View file

@ -10,7 +10,9 @@ int scanf(char const * restrict fmt, ...)
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
__scanf_start(&in);
int count = __scanf(&in, fmt, &args); int count = __scanf(&in, fmt, &args);
__scanf_end(&in);
va_end(args); va_end(args);
return count; return count;

View file

@ -231,10 +231,6 @@ int __scanf(
/* Number of successful assignments */ /* Number of successful assignments */
int validrets = 0; int validrets = 0;
__scanf_start( in );
// TODO: No __scanf_end() in any of the "return validrets"!!
for(int pos = 0; format[pos]; pos++) { for(int pos = 0; format[pos]; pos++) {
if(format[pos] == ' ') { if(format[pos] == ' ') {
__skip_spaces(in); __skip_spaces(in);
@ -366,6 +362,5 @@ int __scanf(
} }
} }
__scanf_end( in );
return validrets; return validrets;
} }

View file

@ -3,7 +3,6 @@
int sscanf(const char * restrict str, char const * restrict fmt, ...) int sscanf(const char * restrict str, char const * restrict fmt, ...)
{ {
/* This is valid even if str=NULL. */
struct __scanf_input in = { struct __scanf_input in = {
.str = str, .str = str,
}; };
@ -11,7 +10,9 @@ int sscanf(const char * restrict str, char const * restrict fmt, ...)
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
__scanf_start(&in);
int count = __scanf(&in, fmt, &args); int count = __scanf(&in, fmt, &args);
__scanf_end(&in);
va_end(args); va_end(args);
return count; return count;

View file

@ -7,5 +7,8 @@ int vfscanf(FILE * restrict fp, char const * restrict fmt, va_list args)
.fp = fp, .fp = fp,
}; };
return __scanf(&in, fmt, &args); __scanf_start(&in);
int rc = __scanf(&in, fmt, &args);
__scanf_end(&in);
return rc;
} }

View file

@ -7,5 +7,8 @@ int vscanf(char const * restrict fmt, va_list args)
.fp = stdin, .fp = stdin,
}; };
return __scanf(&in, fmt, &args); __scanf_start(&in);
int rc = __scanf(&in, fmt, &args);
__scanf_end(&in);
return rc;
} }

View file

@ -8,5 +8,8 @@ int vsscanf(const char * restrict str, char const * restrict fmt, va_list args)
.str = str, .str = str,
}; };
return __scanf(&in, fmt, &args); __scanf_start(&in);
int rc = __scanf(&in, fmt, &args);
__scanf_end(&in);
return rc;
} }