From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102340 invoked by alias); 2 Aug 2017 11:36:17 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 100936 invoked by uid 89); 2 Aug 2017 11:36:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.3 required=5.0 tests=AWL,BAYES_00,FOREIGN_BODY,RCVD_IN_DNSWL_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=no version=3.3.2 spammy=diese, H*r:sk:zimbra., H*r:192.168.96, nachricht X-HELO: dedi548.your-server.de Received: from dedi548.your-server.de (HELO dedi548.your-server.de) (85.10.215.148) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Aug 2017 11:36:14 +0000 Received: from [78.47.166.52] (helo=sslproxy04.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dcrwi-0002Lq-FS for newlib@sourceware.org; Wed, 02 Aug 2017 13:36:12 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy04.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dcrwi-0000Nm-7I for newlib@sourceware.org; Wed, 02 Aug 2017 13:36:12 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 863852A001D for ; Wed, 2 Aug 2017 13:36:27 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 9FNMsyDvs-1g for ; Wed, 2 Aug 2017 13:36:25 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 588EE2A004F for ; Wed, 2 Aug 2017 13:36:25 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id oLAjHTShWNie for ; Wed, 2 Aug 2017 13:36:25 +0200 (CEST) Received: from [192.168.96.129] (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 3FB4A2A001D for ; Wed, 2 Aug 2017 13:36:25 +0200 (CEST) To: Newlib From: Sebastian Huber Subject: Broken getchar() and putchar() macros? Message-ID: <80e430fc-e931-d9a0-173e-8a66e2a494b6@embedded-brains.de> Date: Wed, 02 Aug 2017 11:36:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00715.txt.bz2 Hello, we have via #define getchar() getc(stdin) #define putchar(x) putc(x, stdout) which is #ifndef __CYGWIN__ #ifndef lint #define getc(fp) __sgetc_r(_REENT, fp) #define putc(x, fp) __sputc_r(_REENT, x, fp) #endif /* lint */ #endif /* __CYGWIN__ */ #endif /* __cplusplus */ which is mostly #define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p) #define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p) which is /* * The __sfoo macros are here so that we can * define function versions in the C library. */ #define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ?=20 __srget_r(__ptr, __f) : (int)(*(__f)->_p++)) _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) { #ifdef __SCLE if ((_p->_flags & __SCLE) && _c =3D=3D '\n') __sputc_r (_ptr, '\r', _p); #endif if (--_p->_w >=3D 0 || (_p->_w >=3D _p->_lbfsize && (char)_c !=3D '\n'= )) return (*_p->_p++ =3D _c); else return (__swbuf_r(_ptr, _c, _p)); } which modifies FILE members without protection of the FILE lock! We also have via : int _EXFUN(getchar, (void)); int _EXFUN(putchar, (int)); Which are defined in using #undef putchar and #undef getchar: libc/stdio/putchar.c libc/stdio/getchar.c These function use the FILE lock eventually. What is the purpose of these macros? We had some crashes, due to an=20 invalid FILE::_w value during concurrent output to stdout. --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG.