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 26483 invoked from network); 10 Feb 2022 03:10:01 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 10 Feb 2022 03:10:01 -0000 Received: (qmail 5636 invoked by uid 550); 10 Feb 2022 03:09: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 5601 invoked from network); 10 Feb 2022 03:09:58 -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=PUXq+7KTy6EiiSidoDjMPrMVx04pE0PcxhdCPrII298=; b=jB2UhmqhwhMbK9MA8XPK86nyu5m/fa7BKtgKaGYu2mRDlF+BZx5rmrujdd36x6Yvfy 4RwFveD3Urvm353xXYEKit6ZwPAjbCXMGg8WgV1uYHMcEWkBUDxFh4uCYHZwoY2GJJWa NLrcb3LuEcEmjG+AvDt9qEN/rjAGzoG+lEOYW5dV5SKrsH1w/T58cjoSpHbcCrnCague K1ZpNK6ehXgDvsjH4mcyhBtuIdtqL56KGRMcR10WJ6EQjhDJ93ffPbO1WqukmqeWQpoQ TEZMv06Pu3TzZpPaPxsnuetLpVcG9jz95qpwL2N4+IUPdlSTQbCLhAZe0hBcRAIGbL27 QnMw== 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=PUXq+7KTy6EiiSidoDjMPrMVx04pE0PcxhdCPrII298=; b=63WfdP4RouuAC/VB0uEtEw4lbDH89FOnNnBo2xvCn17rK4N/iwL3HBBdP3RSei0YRd 7uURBgbKfDHazaFuFl3Xbb97nCk4+8QyGSm0EhqLuJpMANKLk9eU1WNLjLOHQhDx7vtQ BrJ2N9jrR2PwXHvjU0oPKbCjjAiRKlrN2RtwvSKdZc4s1UEuc/o+YfpYA3Ki5kJMN5AF diEFtMvY/17TymGE2i+i3yVxfEKorej2sUjEaVfafdQ9GCZzFmqlkTI8FTGWryeZog9e LFPHxf4gS/K/NLWPRzMbIBPLjarIPJ+JJMMJHFF4VfH3eTA3HNClm5y4Bc+L0U2HEQbQ U8jQ== X-Gm-Message-State: AOAM531a+JAPrml0sEfUT4yNKZLWDB3ImDF3zgBMsDgZ7zUS8cc4lN7f 76YijjVQZWP9D9/J40ubnAQvHUrjqFs= X-Google-Smtp-Source: ABdhPJztlnrAJeicxgrBG5zrI/PHVZlnG2LsYpjoNjZwO6FUtqPDwBeYF8Vfw6ClBQOiKWoZePhMhQ== X-Received: by 2002:a17:90b:4f46:: with SMTP id pj6mr555190pjb.43.1644462586098; Wed, 09 Feb 2022 19:09:46 -0800 (PST) From: Pinghao Wu To: musl@lists.openwall.com Cc: Pinghao Wu Date: Thu, 10 Feb 2022 11:08:13 +0800 Message-Id: <20220210030813.1943-1-xdavidwuph@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v2] 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. --- v2: move error checking into the loop. src/stdio/fgetws.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c index b08b3049..cffff84a 100644 --- a/src/stdio/fgetws.c +++ b/src/stdio/fgetws.c @@ -12,18 +12,22 @@ 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; + int err = 0; for (; n; n--) { + /* 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 = __fgetwc_unlocked(f); - if (c == WEOF) break; + if (c == WEOF) { + if (ferror(f) || errno == EILSEQ) err = 1; + break; + } *p++ = c; if (c == '\n') break; } *p = 0; - if (ferror(f) || errno==EILSEQ) p = s; + if (err) p = s; FUNLOCK(f); -- 2.35.1