The Windows HANDLE type, despite being a `void *', does not actually
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 29 Aug 2006 18:32:44 +0000 (18:32 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Tue, 29 Aug 2006 18:32:44 +0000 (18:32 +0000)
behave like a pointer. In particular, the right thing to set a
HANDLE to to indicate that it's invalid is INVALID_HANDLE_VALUE, not
NULL. Crack down on sloppy use of NULL HANDLEs across all Windows
code.

(There is one oddity, which is that {Create,Open}FileMapping are
documented to return a NULL HANDLE instead of INVALID_HANDLE_VALUE
on failure. Shrug. If MS want to be inconsistent, I suppose I have
to live with it.)

git-svn-id: svn://svn.tartarus.org/sgt/putty@6833 cda61777-01e9-0310-a592-d414129be87e

windows/window.c
windows/winpgntc.c
windows/winser.c
windows/winsftp.c

index 4855de5..d58111f 100644 (file)
@@ -1964,11 +1964,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                    sa.nLength = sizeof(sa);
                    sa.lpSecurityDescriptor = NULL;
                    sa.bInheritHandle = TRUE;
-                   filemap = CreateFileMapping((HANDLE) 0xFFFFFFFF,
+                   filemap = CreateFileMapping(INVALID_HANDLE_VALUE,
                                                &sa,
                                                PAGE_READWRITE,
                                                0, sizeof(Config), NULL);
-                   if (filemap) {
+                   if (filemap && filemap != INVALID_HANDLE_VALUE) {
                        p = (Config *) MapViewOfFile(filemap,
                                                     FILE_MAP_WRITE,
                                                     0, 0, sizeof(Config));
index 2259e6a..033fd5f 100644 (file)
@@ -85,7 +85,7 @@ int agent_query(void *in, int inlen, void **out, int *outlen,
     mapname = dupprintf("PageantRequest%08x", (unsigned)GetCurrentThreadId());
     filemap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
                                0, AGENT_MAX_MSGLEN, mapname);
-    if (!filemap)
+    if (filemap == NULL || filemap == INVALID_HANDLE_VALUE)
        return 1;                      /* *out == NULL, so failure */
     p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
     memcpy(p, in, inlen);
index 1213d4a..cd31b5a 100644 (file)
@@ -29,11 +29,11 @@ static void serial_terminate(Serial serial)
        handle_free(serial->in);
        serial->in = NULL;
     }
-    if (serial->port) {
+    if (serial->port != INVALID_HANDLE_VALUE) {
        if (serial->break_in_progress)
            ClearCommBreak(serial->port);
        CloseHandle(serial->port);
-       serial->port = NULL;
+       serial->port = INVALID_HANDLE_VALUE;
     }
 }
 
@@ -208,7 +208,7 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
     const char *err;
 
     serial = snew(struct serial_backend_data);
-    serial->port = NULL;
+    serial->port = INVALID_HANDLE_VALUE;
     serial->out = serial->in = NULL;
     serial->bufsize = 0;
     serial->break_in_progress = FALSE;
@@ -391,7 +391,7 @@ static void serial_provide_logctx(void *handle, void *logctx)
 static int serial_exitcode(void *handle)
 {
     Serial serial = (Serial) handle;
-    if (serial->port != NULL)
+    if (serial->port != INVALID_HANDLE_VALUE)
         return -1;                     /* still connected */
     else
         /* Exit codes are a meaningless concept with serial ports */
index f0f0e30..5293e00 100644 (file)
@@ -431,7 +431,7 @@ char *dir_file_cat(char *dir, char *file)
  * Be told what socket we're supposed to be using.
  */
 static SOCKET sftp_ssh_socket = INVALID_SOCKET;
-static HANDLE netevent = NULL;
+static HANDLE netevent = INVALID_HANDLE_VALUE;
 char *do_select(SOCKET skt, int startup)
 {
     int events;
@@ -481,11 +481,11 @@ int do_eventsel_loop(HANDLE other_event)
     handles = sresize(handles, nhandles+2, HANDLE);
     nallhandles = nhandles;
 
-    if (netevent)
+    if (netevent != INVALID_HANDLE_VALUE)
        handles[netindex = nallhandles++] = netevent;
     else
        netindex = -1;
-    if (other_event)
+    if (other_event != INVALID_HANDLE_VALUE)
        handles[otherindex = nallhandles++] = other_event;
     else
        otherindex = -1;
@@ -625,7 +625,7 @@ int ssh_sftp_loop_iteration(void)
 
        return 0;
     } else {
-       return do_eventsel_loop(NULL);
+       return do_eventsel_loop(INVALID_HANDLE_VALUE);
     }
 }