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=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26372 invoked from network); 9 Feb 2022 18:49:12 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 9 Feb 2022 18:49:12 -0000 Received: (qmail 7781 invoked by uid 550); 9 Feb 2022 18:49:10 -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 7749 invoked from network); 9 Feb 2022 18:49:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kt45gwvojyOoymusSLUa31AR5pIPfdFHylAV1lsZqIQ=; b=bRp4ZrlISWpM99wutHcJX130mRvhO7xULl9ynCmalBA+6MGCR3lnhKmJ4VAFZ4EdHp cI2CljUlgc6QkETP/GuKfgnP1dBJlpviOpfjy9wedJgTSlTiuHzLIS1n1XBBJmZNf5sz Gx3q/U+E81KiHhWtpYnhswRJIHC3bWwSav8gt3+rNYT0Dcw7daQeWRaqnQSQV6q0u2bL vMYdUjFdiuPcQ6U1aYZ8DoAleyd/iviVFKJ15FNdirpLPkVmj4s5eAVo4uJhTSzCcQaJ C8iXWd5h0jU8AvS2kaTwOJ6/ktwsyDd87n8T+xVhEKIcwuJ0KtGLjmfi/jlurOM5qsLU 0Ljw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kt45gwvojyOoymusSLUa31AR5pIPfdFHylAV1lsZqIQ=; b=yWRPhxGlUWQggDxoEDTP2TMejEpp6ehLLgnM9dJyVgtC6vIJ1N5jbc0A4NyHhVY197 ugnExQ4L6BMTec4ux4XE3EDlWvOXC3l0aadf0dhBl7CnyGcFMKzU1ERoqicBK643LxEg beMqf3eIEV6TwirX2MawvrMeeTxQPNSB1905+mzmB3pJsP+7n1ZVKUICOfy7LuL5vuyG n91XBqA0ko6al8ADyQYUv1USgYv09a3eo7OmuC5eR8WqSn51IJ7HFkfEllkQHEzbDKYM C2DVsN/DGOeF4vP7x/4wKrnkYWVAVZO/EyEiZxWCFHmc88awBQiF+VjOs04V3bl1NqoP zrHQ== X-Gm-Message-State: AOAM532Yn9t/Gp8INmy43AKiB23lZDBGEIJxHZLvI2UeQbUcSai1ouT1 ZUvPa5yaFKTz177rUWrgyrfIKUArqrY= X-Google-Smtp-Source: ABdhPJzd8n74IznH8wXCPGjhCETUoSXrdCGh1d/l0gb2Y/M6pSQBSpqdfId2FT5mlFCyPV4ycNtYrg== X-Received: by 2002:a63:8149:: with SMTP id t70mr2935407pgd.433.1644432537085; Wed, 09 Feb 2022 10:48:57 -0800 (PST) From: Pinghao Wu To: musl@lists.openwall.com Cc: Pinghao Wu Date: Thu, 10 Feb 2022 02:47:36 +0800 Message-Id: <20220209184736.26792-1-xdavidwuph@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] fgetws: fix checking for fgetwc errors This corrects checking for fgetwc errors by arming dummy errno before each invocation, and checking errors only if it returns WEOF. --- src/stdio/fgetws.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c index b08b3049..edcd769b 100644 --- a/src/stdio/fgetws.c +++ b/src/stdio/fgetws.c @@ -12,18 +12,19 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) FLOCK(f); - /* Setup a dummy errno so we can detect EILSEQ. This is - * the only way to catch encoding errors in the form of a - * partial character just before EOF. */ - errno = EAGAIN; + wint_t c; for (; n; n--) { - wint_t c = __fgetwc_unlocked(f); + /* Setup a dummy errno so we can detect EILSEQ. This is + * the only way to catch encoding errors in the form of a + * partial character just before EOF. */ + errno = EAGAIN; + c = __fgetwc_unlocked(f); if (c == WEOF) break; *p++ = c; if (c == '\n') break; } *p = 0; - if (ferror(f) || errno==EILSEQ) p = s; + if (c == WEOF && (ferror(f) || errno==EILSEQ)) p = s; FUNLOCK(f); -- 2.35.1