any1 / neatvnc

A liberally licensed VNC server library with a clean interface
ISC License
126 stars 31 forks source link

fix: i386 related data type mismatch #133

Closed RevySR closed 1 week ago

RevySR commented 1 week ago

In i386 ext_clipboard_provide_msg.length is size_t, not uLongf(long unsigned int).

any1 commented 1 week ago

I more generic terms, ext_clipboard_provide_msg.length is size_t regardless of platform, but the function takes unsigned long.

Did you read CONTRIBUTING.md?

RevySR commented 1 week ago

I more generic terms, ext_clipboard_provide_msg.length is size_t regardless of platform, but the function takes unsigned long.

Did you read CONTRIBUTING.md?

Sorry, I misunderstood the CONTRIBUTING document and have resubmitted a new commit msg.

any1 commented 1 week ago

I think there may still be some misunderstanding regarding the structure of commit messages.

To clarify: A good commit message says what was done in the title. E.g. "server: Use correct type for length in compress()". Then, it goes on to say why. E.g. "This fixes data type mismatch on 32 bit systems".

Besides, there exists a simpler solution:

diff --git a/src/server.c b/src/server.c
index ac15b0b..b94ed0d 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1509,9 +1509,8 @@ static void ext_clipboard_save_provide_msg(struct nvnc* server, const char* text
        memcpy(provide_msg_buf + 4, text, len);
        provide_msg_buf[provide_msg_len - 1] = 0;

-       server->ext_clipboard_provide_msg.length = compressBound(provide_msg_len);
-       server->ext_clipboard_provide_msg.buffer = malloc(
-                       server->ext_clipboard_provide_msg.length);
+       unsigned long length = compressBound(provide_msg_len);
+       server->ext_clipboard_provide_msg.buffer = malloc(length);
        if (!server->ext_clipboard_provide_msg.buffer) {
                nvnc_log(NVNC_LOG_ERROR, "OOM: %m");
                return;
@@ -1519,8 +1518,8 @@ static void ext_clipboard_save_provide_msg(struct nvnc* server, const char* text

        int rc;
        rc = compress((unsigned char*)server->ext_clipboard_provide_msg.buffer,
-                       &server->ext_clipboard_provide_msg.length,
-                       provide_msg_buf, provide_msg_len);
+                       &length, provide_msg_buf, provide_msg_len);
+       server->ext_clipboard_provide_msg.length = length;

        free(provide_msg_buf);
RevySR commented 1 week ago

This fixes data type mismatch on 32 bit systems

Thanks for your help. I've changed it.

any1 commented 1 week ago

Thanks! N.b. it would have been fine to include the compiler error in the message, but this is good enough.

I hope you gave this a quick test, because I sure didn't. :)