From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp26.services.sfr.fr ([93.17.128.21]) by ewsd; Sat Jul 11 10:39:39 EDT 2020 X-mail-filterd: 0.5.0 X-sfr-mailing: LEGIT X-sfr-spamrating: 40 X-sfr-spam: not-spam Received: from cauchy.polynum.local (89.121.198.77.rev.sfr.net [77.198.121.89]) by msfrf2626.sfr.fr (SMTP Server) with ESMTP id D2C001C00042A; Sat, 11 Jul 2020 16:39:23 +0200 (CEST) Received: from cauchy.polynum.local (89.121.198.77.rev.sfr.net [77.198.121.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by msfrf2626.sfr.fr (SMTP Server) with ESMTPS; Sat, 11 Jul 2020 16:39:23 +0200 (CEST) Received: from cauchy.polynum.local (localhost [127.0.0.1]) by cauchy.polynum.local (8.15.2/8.15.2) with ESMTP id 06BEdNQW000169; Sat, 11 Jul 2020 16:39:23 +0200 (CEST) Received: (from tlaronde@localhost) by cauchy.polynum.local (8.15.2/8.14.9/Submit) id 06BEdMJw000200; Sat, 11 Jul 2020 16:39:22 +0200 (CEST) X-Authentication-Warning: cauchy.polynum.local: tlaronde set sender to thierry.laronde@sfr.fr using -f Date: Sat, 11 Jul 2020 16:39:22 +0200 From: tlaronde@polynum.com To: ori@eigenstate.org Cc: 9front@9front.org Subject: Re: [FOUND] [9front] putc/fputc incorrect return Message-ID: <20200711143922.GB563@polynum.com> References: <20200709182924.GA465@polynum.com> <9886E456A839F5CDF03974A2426A0518@eigenstate.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9886E456A839F5CDF03974A2426A0518@eigenstate.org> User-Agent: Mutt/1.5.24 (2015-08-30) List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: responsive replication factory polling locator Here is the simple code exhibiting the problem. There are three components: 1) int is negative; 2) there are at least two successive calls; 3) the stream is neither stdout nor stderr. #include #include int main(int argc, char *argv[]) { FILE *fp; short w; if ( (fp = fopen("/tmp/bug.tfm", "wb")) == NULL ) { (void)fprintf(stderr, "Unable to open '/tmp/bug.tfm' for writing.\n"); return 1; } /* Writing successively negative word on the file stream: bug. */ w = 0xffaa; (void)fprintf(stderr, "\nWriting big endian '%#hx' on file stream returned" " -> %#x %#x\n", w, putc(w >> 8, fp), putc(w, fp)); /* On stdout, no problem. */ (void)fprintf(stderr, "\nWriting big endian '%#hx' on stdout returned" " -> %#x %#x\n", w, putc(w >> 8, stdout), putc(w, stdout)); return 0; } Best, -- Thierry Laronde http://www.kergis.com/ http://www.sbfa.fr/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C