From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: Newlib <newlib@sourceware.org>
Subject: Broken getchar() and putchar() macros?
Date: Wed, 02 Aug 2017 11:36:00 -0000 [thread overview]
Message-ID: <80e430fc-e931-d9a0-173e-8a66e2a494b6@embedded-brains.de> (raw)
Hello,
we have via <stdio.h>
#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 ?
__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 == '\n')
__sputc_r (_ptr, '\r', _p);
#endif
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
return (*_p->_p++ = _c);
else
return (__swbuf_r(_ptr, _c, _p));
}
which modifies FILE members without protection of the FILE lock!
We also have via <stdio.h>:
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
invalid FILE::_w value during concurrent output to stdout.
--
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äftliche Mitteilung im Sinne des EHUG.
next reply other threads:[~2017-08-02 11:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-02 11:36 Sebastian Huber [this message]
2017-08-02 12:37 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=80e430fc-e931-d9a0-173e-8a66e2a494b6@embedded-brains.de \
--to=sebastian.huber@embedded-brains.de \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).