Adding file descriptor attribute(s) to gcc and glibc
Szabolcs Nagy
szabolcs.nagy@arm.com
Thu Jul 14 08:30:32 GMT 2022
The 07/13/2022 12:55, David Malcolm wrote:
> On Wed, 2022-07-13 at 16:01 +0200, Florian Weimer wrote:
> > * David Malcolm:
> GCC trunk's -fanalyzer implements the new warnings via a state machine
> for file-descriptor values; it currently has rules for handling "open",
> "close", "read", and "write", and these functions are currently hard-
> coded inside the analyzer.
>
> Here are some examples on Compiler Explorer of what it can/cannot
> detect:
> https://godbolt.org/z/nqPadvM4f
>
> Probably the most important one IMHO is the leak detection.
nice.
> Would it be helpful to have some kind of attribute for "returns a new
> open FD"? Are there other ways to close a FD other than calling
> "close" on it? (Would converting that to some kind of "closes"
> attribute be a good idea?)
dup2(oldfd, newfd)
dup3(oldfd, newfd, flags)
closes newfd (and also opens it to be a dup of oldfd)
unless the call fails.
close_range(first, last, flags)
fclose(fdopen(fd, mode))
but users can write all sorts of wrappers around close too.
>
> Are there any other "magic" values for file-descriptors we should be
> aware of?
>
mmap may require fd==-1 for anonymous maps.
More information about the Gcc
mailing list