On Wednesday 26 January 2022 00:23:49 LIU Hao wrote: > 在 2022-01-16 22:44, Pali Rohár 写道: > > diff --git a/mingw-w64-crt/stdio/scanf2-argcount-template.c > > b/mingw-w64-crt/stdio/scanf2-argcount-template.c > > new file mode 100644 > > index 000000000000..c07e11797c39 > > --- /dev/null > > +++ b/mingw-w64-crt/stdio/scanf2-argcount-template.c > > @@ -0,0 +1,22 @@ > > +/** > > + * This file has no copyright assigned and is placed in the Public Domain. > > + * This file is part of the mingw-w64 runtime package. > > + * No warranty is given; refer to the file DISCLAIMER.PD within this > > package. > > + */ > > + > > +#include <stddef.h> > > + > > +size_t FUNC(const TYPE *format); > > +size_t FUNC(const TYPE *format) > > +{ > > + size_t count = 0; > > + for (; *format; format++) { > > + if (*format != (TYPE)'%') > > + continue; > > + format++; > > + if (*format == (TYPE)'%' || *format == (TYPE)'*') > > + continue; > > + count++; > > + } > > + return count; > > +} > > > > I am afraid there are two issues about this function: > > One is that it may read pass the end of the format string if it contains a > stray `%` at the end (which however is undefined behavior) but I don't think > it is a good idea to not handle it properly.
Ok. This can be fixed pretty easily. > The other is that `%` does not necessarily start an argument specifier. For > example `"abc%[01%]"` contains only one specifier for one argument, and this > function produces a wrong result. Yes, this is truth. However amd64 asm code already reads more pointers from stack (when number of them is smaller then number of arguments needed to pass via registers when doing function call), so I think that this function can be documented that returns "minimal number of arguments". So it is really an issue? Or should be function extended to skip all characters between [ and ]? _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public