aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-10-18 16:22:33 -0700
committerGuy Harris <gharris@sonic.net>2021-10-18 16:22:33 -0700
commit3fe96028d2edbfc4b6d57b7219f54f7171c461e3 (patch)
tree94398b94158d2c15a3446786cbc4689a495b8fc2
parenta2e877d39785a6c05b723e9d62865dab3feee5a6 (diff)
Add a comment to explain a cast done in file_fdopen().
-rw-r--r--wiretap/file_wrappers.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c
index f82deb3849..1bd219408a 100644
--- a/wiretap/file_wrappers.c
+++ b/wiretap/file_wrappers.c
@@ -1132,6 +1132,24 @@ file_fdopen(int fd)
*
* If the value is too big to fit into a guint,
* just use the maximum read buffer size.
+ *
+ * On top of that, the Single UNIX Speification says that
+ * st_blksize is of type blksize_t, which is a *signed*
+ * integer type, and, at minimum, macOS 11.6 and Linux 5.14.11's
+ * include/uapi/asm-generic/stat.h define it as such.
+ *
+ * However, other OSes might make it unsigned, and older versions
+ * of OSes that currently make it signed might make it unsigned,
+ * so we try to avoid warnings from that.
+ *
+ * We cast MAX_READ_BUF_SIZE to long in order to avoid the
+ * warning, although it might introduce warnings on platforms
+ * where st_blocksize is unsigned; we'll deal with that if
+ * it ever shows up as an issue.
+ *
+ * MAX_READ_BUF_SIZE is < the largest *signed* 32-bt integer,
+ * so casting it to long won't turn it into a negative number.
+ * (We only support 32-bit and 64-bit 2's-complement platforms.)
*/
if (st.st_blksize <= (long)MAX_READ_BUF_SIZE)
want = (guint)st.st_blksize;