diff --git a/libc/stdio/lib_ungetc.c b/libc/stdio/lib_ungetc.c index 9d14499d7b7..bf8699a384d 100644 --- a/libc/stdio/lib_ungetc.c +++ b/libc/stdio/lib_ungetc.c @@ -94,10 +94,17 @@ int ungetc(int c, FAR FILE *stream) int nungotten; #endif + /* Verify that a non-NULL stream was provided */ + + if (!stream) + { + set_errno(EBADF); + return EOF; + } + /* Stream must be open for read access */ - if ((stream && stream->fs_fd < 0) || - ((stream->fs_oflags & O_RDOK) == 0)) + if ((stream->fs_fd < 0) || ((stream->fs_oflags & O_RDOK) == 0)) { set_errno(EBADF); return EOF;