diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index c13b6970b21a..8482d0d57d36 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -283,6 +283,7 @@ _fseeko(fp, offset, whence, ltest) fp->_r -= n; } fp->_flags &= ~__SEOF; + memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t)); return (0); /* @@ -293,6 +294,11 @@ _fseeko(fp, offset, whence, ltest) if (__sflush(fp) || (ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR) return (-1); + if (ltest && ret > LONG_MAX) { + fp->_flags |= __SERR; + errno = EOVERFLOW; + return (-1); + } /* success: clear EOF indicator and discard ungetc() data */ if (HASUB(fp)) FREEUB(fp); @@ -301,10 +307,5 @@ _fseeko(fp, offset, whence, ltest) /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t)); - if (ltest && ret > LONG_MAX) { - fp->_flags |= __SERR; - errno = EOVERFLOW; - return (-1); - } return (0); }