mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-02 02:32:27 +00:00
Fix some static analysis issues
This commit is contained in:
parent
fb54604b31
commit
f147d3dde9
30 changed files with 375 additions and 266 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
@ -37,8 +38,8 @@
|
|||
* @return stream object if successful, or NULL w/ errno
|
||||
*/
|
||||
FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
|
||||
int fd;
|
||||
FILE *res;
|
||||
int fd, fd2;
|
||||
unsigned flags;
|
||||
flags = fopenflags(mode);
|
||||
flockfile(stream);
|
||||
|
@ -46,19 +47,30 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
|
|||
if (pathname) {
|
||||
/* open new stream, overwriting existing alloc */
|
||||
if ((fd = open(pathname, flags, 0666)) != -1) {
|
||||
dup3(fd, stream->fd, flags & O_CLOEXEC);
|
||||
fd2 = dup3(fd, stream->fd, flags & O_CLOEXEC);
|
||||
close(fd);
|
||||
stream->iomode = flags;
|
||||
stream->beg = 0;
|
||||
stream->end = 0;
|
||||
res = stream;
|
||||
if (fd2 != -1) {
|
||||
stream->fd = fd2;
|
||||
stream->iomode = flags;
|
||||
stream->beg = 0;
|
||||
stream->end = 0;
|
||||
res = stream;
|
||||
} else {
|
||||
res = NULL;
|
||||
}
|
||||
} else {
|
||||
res = NULL;
|
||||
}
|
||||
} else {
|
||||
fcntl(stream->fd, F_SETFD, !!(flags & O_CLOEXEC));
|
||||
fcntl(stream->fd, F_SETFL, flags & ~O_CLOEXEC);
|
||||
res = stream;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wanalyzer-fd-use-without-check"
|
||||
if (fcntl(stream->fd, F_SETFD, !!(flags & O_CLOEXEC)) != -1 &&
|
||||
fcntl(stream->fd, F_SETFL, flags & ~O_CLOEXEC) != -1) {
|
||||
#pragma GCC diagnostic pop
|
||||
res = stream;
|
||||
} else {
|
||||
res = NULL;
|
||||
}
|
||||
}
|
||||
funlockfile(stream);
|
||||
return res;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue