stream_getc: use lib_stream_eof instead of EOF

Will case scanftest break #14778, at " %4c%n" case.
scanf use INT_MAX cause EOF break.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
buxiasen
2024-11-22 22:40:47 +08:00
committed by Xiang Xiao
parent f3213efc7f
commit 3e24aab208
8 changed files with 23 additions and 14 deletions
+1
View File
@@ -50,6 +50,7 @@
#define lib_stream_puts(stream, buf, len) \
((FAR struct lib_outstream_s *)(stream))->puts( \
(FAR struct lib_outstream_s *)(stream), buf, len)
#define lib_stream_eof(c) ((c) <= 0)
#define lib_stream_getc(stream) \
((FAR struct lib_instream_s *)(stream))->getc( \
(FAR struct lib_instream_s *)(stream))
+3 -3
View File
@@ -250,21 +250,21 @@ static int readstream(FAR struct lib_instream_s *instream,
/* Skip until the beginning of line start code is encountered */
ch = lib_stream_getc(instream);
while (ch != RECORD_STARTCODE && ch != EOF)
while (ch != RECORD_STARTCODE && !lib_stream_eof(ch))
{
ch = lib_stream_getc(instream);
}
/* Skip over the startcode */
if (ch != EOF)
if (!lib_stream_eof(ch))
{
ch = lib_stream_getc(instream);
}
/* Then read, verify, and buffer until the end of line is encountered */
while (ch != EOF && nbytes < (MAXRECORD_ASCSIZE - 1))
while (!lib_stream_eof(ch) && nbytes < (MAXRECORD_ASCSIZE - 1))
{
if (ch == '\n' || ch == '\r')
{
+4 -4
View File
@@ -142,7 +142,7 @@ int kbd_decode(FAR struct lib_instream_s *stream,
/* No, ungotten characters. Check for the beginning of an ESC sequence. */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream */
@@ -166,7 +166,7 @@ int kbd_decode(FAR struct lib_instream_s *stream,
/* Check for ESC-[ */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Return the escape character now. We will
* return the EOF indication next time.
@@ -192,7 +192,7 @@ int kbd_decode(FAR struct lib_instream_s *stream,
/* Get and verify the special keyboard data to decode */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Unget everything and return the ESC character.
*/
@@ -219,7 +219,7 @@ int kbd_decode(FAR struct lib_instream_s *stream,
/* Check for the final semicolon */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Unget everything and return the ESC character.
*/
+5 -5
View File
@@ -180,7 +180,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream,
/* No, ungotten characters. Get the next character from the buffer. */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream (or perhaps an I/O error) */
@@ -204,7 +204,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream,
/* Get the next character from the buffer */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Return the escape character now. We will
* return the EOF indication next time.
@@ -233,7 +233,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream,
/* Get the next character from the buffer */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Return the ESC now; return the following
* characters later.
@@ -281,7 +281,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream,
/* Get the next character from the buffer */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Return the ESC now; return the following
* characters later.
@@ -314,7 +314,7 @@ enum slcdret_e slcd_decode(FAR struct lib_instream_s *stream,
/* Get the next character from the buffer */
ch = lib_stream_getc(stream);
if (ch == EOF)
if (lib_stream_eof(ch))
{
/* End of file/stream. Return the ESC now; return the following
* characters later.
+1 -1
View File
@@ -1149,7 +1149,7 @@ static int vscanf_internal(FAR struct lib_instream_s *stream, FAR int *lastc,
{
size_t nchars = (size_t) (stream->nget - ngetstart);
if (c != EOF)
if (!lib_stream_eof(c))
{
/* One more character already read */
+1 -1
View File
@@ -41,7 +41,7 @@ int vsscanf(FAR const char *buf, FAR const IPTR char *fmt, va_list ap)
/* Initialize a memory stream to freadm from the buffer */
lib_meminstream(&meminstream, buf, INT_MAX);
lib_meminstream(&meminstream, buf, strlen(buf));
/* Then let lib_vscanf do the real work */
+4
View File
@@ -52,6 +52,10 @@ static int stdinstream_getc(FAR struct lib_instream_s *self)
{
self->nget++;
}
else
{
ret = _NX_GETERRVAL(ret);
}
return ret;
}
+4
View File
@@ -51,6 +51,10 @@ static int stdsistream_getc(FAR struct lib_sistream_s *self)
{
self->nget++;
}
else
{
ret = _NX_GETERRVAL(ret);
}
return ret;
}