From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7604 invoked from network); 31 May 2023 14:06:30 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 31 May 2023 14:06:30 -0000 Received: (qmail 22040 invoked by uid 550); 31 May 2023 14:05:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21937 invoked from network); 31 May 2023 14:05:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=WlYwf4gO9L64lCJkrotsd9cudb7A36VPJT53KBNQcZ4=; b=W2isF6vlnFN57D9CyLcZtI8N31nX1N0uHNWu0PyoO8a1K6JyZTx0U64w v2YimcjZb5vBGDIrRBKjAenGvAqwybk2uDOVPk328Lui3xQ8w8WU8uiaN B0ATIgUuauoxBVIRXCefIUIOPH0o15PNzrjTdRAhAQ9AVdlpGdl9NvVW1 4=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Jens.Gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.00,207,1681164000"; d="scan'208";a="110511565" From: Jens Gustedt To: musl@lists.openwall.com Date: Wed, 31 May 2023 16:05:43 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [C23 scanf 3/3] C23: implement wN and wfN specifiers for scanf functions --- src/stdio/vfscanf.c | 30 ++++++++++++++++++++++++++++++ src/stdio/vfwscanf.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index f72ac9c9..f8ace92f 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -41,6 +41,15 @@ static void store_int(void *dest, int size, unsigned long long i) } } +static int getint(unsigned char const**s) { + int i=0; + if (**s != '0') for (; isdigit(**s); (*s)++) { + if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; + else i = 10*i + (**s-'0'); + } + return i; +} + static void *arg_n(va_list ap, unsigned int n) { void *p; @@ -57,6 +66,7 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) { int width; int size; + int fast16; int alloc = 0; int base; const unsigned char *p; @@ -150,6 +160,26 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) case 'L': size = SIZE_L; break; + case 'w': + // See if "fast" is requested. Difference is only + // relevant for a fast type of minimum width 16. + fast16 = SIZE_h; + if (*p == 'f') { + fast16 = SIZE_def; + ++p; + } + switch (getint(&p)) { + default: goto fmt_fail; + case 8: size = SIZE_hh; break; + case 16: size = fast16; break; + case 32: size = SIZE_def; break; +#if UINTPTR_MAX >= UINT64_MAX + case 64: size = SIZE_l; break; +#else + case 64: size = SIZE_ll; break; +#endif + } + break; case 'b': case 'd': case 'i': case 'o': case 'u': case 'x': case 'a': case 'e': case 'f': case 'g': case 'A': case 'E': case 'F': case 'G': case 'X': diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c index 17f5a2f9..6fe2749c 100644 --- a/src/stdio/vfwscanf.c +++ b/src/stdio/vfwscanf.c @@ -41,6 +41,15 @@ static void store_int(void *dest, int size, unsigned long long i) } } +static int getint(wchar_t const**s) { + int i=0; + if (**s != L'0') for (i=0; iswdigit(**s); (*s)++) { + if (i > INT_MAX/10U || **s-L'0' > INT_MAX-10*i) i = -1; + else i = 10*i + (**s-L'0'); + } + return i; +} + static void *arg_n(va_list ap, unsigned int n) { void *p; @@ -87,6 +96,7 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) { int width; int size; + int fast16; int alloc; const wchar_t *p; int c, t; @@ -173,6 +183,26 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) case 'L': size = SIZE_L; break; + case 'w': + // See if "fast" is requested. Difference is only + // relevant for a fast type of minimum width 16. + fast16 = SIZE_h; + if (*p == 'f') { + fast16 = SIZE_def; + ++p; + } + switch (getint(&p)) { + default: goto fmt_fail; + case 8: size = SIZE_hh; break; + case 16: size = fast16; break; + case 32: size = SIZE_def; break; +#if UINTPTR_MAX >= UINT64_MAX + case 64: size = SIZE_l; break; +#else + case 64: size = SIZE_ll; break; +#endif + } + break; case 'b': case 'd': case 'i': case 'o': case 'u': case 'x': case 'a': case 'e': case 'f': case 'g': case 'A': case 'E': case 'F': case 'G': case 'X': -- 2.34.1