[PATCH] Win32: Don't discards const qualifiers for WriteFile

Kentaro Hayashi kenhys at gmail.com
Tue Nov 27 05:07:45 UTC 2018


Hi,
It seems that there is a mismatch between ngx_write_fd and WriteFile
prototype.
I've attached a patch for it.

# HG changeset patch
# User hayashi at clear-code.com
# Date 1543294459 -32400
#      Tue Nov 27 13:54:19 2018 +0900
# Branch use-const-void-pointer
# Node ID 04809b6012bd8a744e3beded6fc385cdb3f788ee
# Parent  a7ff19afbb14795fef14f599a304d0ad21052b70
Win32: Don't discards const qualifiers for WriteFile

The 2nd argument of ngx_write_fd() is declared as
void pointer instead of const void pointer.
It means that void pointer is passed to WriteFile which accepts
LPCVOID pointer, instead of LPVOID. Thus const qualifier isn't respected.

ref.
https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-writefile

It causes a compile warning.

diff -r a7ff19afbb14 -r 04809b6012bd src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c  Mon Nov 26 18:29:56 2018 +0300
+++ b/src/os/win32/ngx_files.c  Tue Nov 27 13:54:19 2018 +0900
@@ -175,7 +175,7 @@


 ssize_t
-ngx_write_fd(ngx_fd_t fd, void *buf, size_t size)
+ngx_write_fd(ngx_fd_t fd, const void *buf, size_t size)
 {
     u_long  n;

diff -r a7ff19afbb14 -r 04809b6012bd src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h  Mon Nov 26 18:29:56 2018 +0300
+++ b/src/os/win32/ngx_files.h  Tue Nov 27 13:54:19 2018 +0900
@@ -107,7 +107,7 @@
 #define ngx_read_fd_n               "ReadFile()"


-ssize_t ngx_write_fd(ngx_fd_t fd, void *buf, size_t size);
+ssize_t ngx_write_fd(ngx_fd_t fd, const void *buf, size_t size);
 #define ngx_write_fd_n              "WriteFile()"

-- 
Kentaro Hayashi <kenhys at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20181127/3309e410/attachment.html>


More information about the nginx-devel mailing list