[PATCH] Win32: Don't discards const qualifiers for WriteFile
Maxim Dounin
mdounin at mdounin.ru
Tue Nov 27 13:27:06 UTC 2018
Hello!
On Tue, Nov 27, 2018 at 02:07:45PM +0900, Kentaro Hayashi wrote:
> 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.
Could you please elaborate a bit more about the compile warning?
Which compiler you use, how the warning looks like?
The const qualifier is only important when it's removed from a
variable - that is, when you pass something declared as "const"
into a function with non-const argument. That is, when you pass a
constant variable into a function which does not promise to handle
it as a constant variable. The opposite is perfectly fine, so you
can safely pass a non-constant variable into a function which
promises not to change the variable. From this point of view
there are no problems in ngx_write_fd(), it simply passes a
non-constant string to a function which promises not to change
this string.
[...]
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list