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

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

commit 9ed4fa7f9abde2a92837618b15df8c9b4c66c59f
Author: dengwenqi <[email protected]>
AuthorDate: Thu May 14 10:57:48 2026 +0800

    drivers/serial/pty: cast the iscntrl() argument to unsigned char in 
pty_read()
    
    The iscntrl() call in pty_read() was receiving 'ch & 0xff' where 'ch'
    is declared as 'char' (implementation-defined signedness). Although
    the bitwise mask yields a value in [0, 255], Coverity flags this as a
    MISRA C-2012 Rule 21.13 violation because the argument expression is
    not directly representable as unsigned char in the type system.
    
    Replace the mask with an explicit (unsigned char) cast, which is the
    canonical idiom recommended by MISRA for <ctype.h> functions and
    makes the type-narrowing intent explicit to static analyzers.
    Behavior is unchanged: the cast produces the same [0, 255] range.
    
    Signed-off-by: dengwenqi <[email protected]>
---
 drivers/serial/pty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index 5812e22d903..689ee1cd0d8 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -547,7 +547,7 @@ static ssize_t pty_read(FAR struct file *filep, FAR char 
*buffer, size_t len)
 
           /* Record the character can be echo */
 
-          if (!iscntrl(ch & 0xff) && n++ == 0)
+          if (!iscntrl((unsigned char)ch) && n++ == 0)
             {
               j = i;
             }

Reply via email to