This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new d5563b10ccd include/limits.h: Set IOV_MAX to 1024
d5563b10ccd is described below

commit d5563b10ccd6dcccd68bc97d0cc663d5b5c278ee
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Nov 2 12:41:54 2026 +0100

    include/limits.h: Set IOV_MAX to 1024
    
    IOV_MAX is INT_MAX because NuttX has no upper limit on the number of I/O
    vectors of readv() and writev().  But programs declare arrays of IOV_MAX
    vectors, also on the stack.  With INT_MAX such an array has 32 GiB on a
    64-bit target, and the program stops with a segmentation fault when it
    clears the array.  On a 32-bit target the array does not compile.
    
    IOV_MAX is now 1024, the value of Linux and the BSDs.  POSIX requires at
    least 16 (_XOPEN_IOV_MAX).  sysconf(_SC_IOV_MAX) now gives it (before: -1
    with ENOSYS).  readv() and writev() still accept more vectors.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 include/limits.h               | 8 ++++----
 libs/libc/unistd/lib_sysconf.c | 3 +++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/limits.h b/include/limits.h
index 44140a1e3e8..8ae80cec664 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -279,11 +279,11 @@
 
 #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
 
-/* Required for readv() and writev() */
-
-/* There really is no upper limit on the number of vectors */
+/* Required for readv() and writev().  NuttX has no upper limit, but programs
+ * declare arrays of IOV_MAX vectors: use the value of Linux and the BSDs.
+ */
 
-#define IOV_MAX        INT_MAX
+#define IOV_MAX        1024
 
 #define HOST_NAME_MAX  CONFIG_HOST_NAME_MAX
 
diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c
index 1e3460b1bae..b577d053768 100644
--- a/libs/libc/unistd/lib_sysconf.c
+++ b/libs/libc/unistd/lib_sysconf.c
@@ -289,6 +289,9 @@ long sysconf(int name)
       case _SC_AIO_LISTIO_MAX:
         return AIO_LISTIO_MAX;
 
+      case _SC_IOV_MAX:
+        return IOV_MAX;
+
       default:
 #if 0 /* Assume valid but not implemented for the time being */
         errcode = EINVAL;

Reply via email to