Date: Fri, 24 Feb 2023 19:55:11 +0600 From: NRK <nrk@...root.org> To: musl@...ts.openwall.com Cc: Tamir Duberstein <tamird@...gle.com> Subject: Re: undefined behavior in fread.c On Fri, Feb 24, 2023 at 08:34:14AM -0500, Rich Felker wrote: > Is there any indication that passing NULL as the first argument to > fread is not itself undefined? C99 says the following: | If size or nmemb is zero, fread returns zero and the contents of the | array and the state of the stream remain unchanged. It doesn't explicitly mention weather stream can be NULL or not in case of 0 size/nmemb - but regardless, is there any actual reason for not returning early? The following should be OK as far as I see: - if (!size) nmemb = 0; + if (!size || !nmemb) return 0; or `if (!len) return 0;` could also work if multiplication overflow is not a concern. - NRK
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.