[nginx] Adjusted mmap() type casts.

Maxim Dounin mdounin at mdounin.ru
Wed Jun 4 23:45:29 UTC 2025


details:   http://freenginx.org/hg/nginx/rev/fc202c264ad7
branches:  
changeset: 9371:fc202c264ad7
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Jun 05 02:38:21 2025 +0300
description:
Adjusted mmap() type casts.

Type casting mmap() result explicitly to (u_char *) is only needed on
systems where mmap() returns caddr_t, but on these systems MAP_FAILED
also needs to be casted.  Added appropriate type casts.

diffstat:

 src/os/unix/ngx_shmem.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (30 lines):

diff --git a/src/os/unix/ngx_shmem.c b/src/os/unix/ngx_shmem.c
--- a/src/os/unix/ngx_shmem.c
+++ b/src/os/unix/ngx_shmem.c
@@ -18,7 +18,7 @@ ngx_shm_alloc(ngx_shm_t *shm)
                                 PROT_READ|PROT_WRITE,
                                 MAP_ANON|MAP_SHARED, -1, 0);
 
-    if (shm->addr == MAP_FAILED) {
+    if (shm->addr == (u_char *) MAP_FAILED) {
         ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
                       "mmap(MAP_ANON|MAP_SHARED, %uz) failed", shm->size);
         return NGX_ERROR;
@@ -55,7 +55,7 @@ ngx_shm_alloc(ngx_shm_t *shm)
     shm->addr = (u_char *) mmap(NULL, shm->size, PROT_READ|PROT_WRITE,
                                 MAP_SHARED, fd, 0);
 
-    if (shm->addr == MAP_FAILED) {
+    if (shm->addr == (u_char *) MAP_FAILED) {
         ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
                       "mmap(/dev/zero, MAP_SHARED, %uz) failed", shm->size);
     }
@@ -65,7 +65,7 @@ ngx_shm_alloc(ngx_shm_t *shm)
                       "close(\"/dev/zero\") failed");
     }
 
-    return (shm->addr == MAP_FAILED) ? NGX_ERROR : NGX_OK;
+    return (shm->addr == (u_char *) MAP_FAILED) ? NGX_ERROR : NGX_OK;
 }
 
 


More information about the nginx-devel mailing list