Author: rfm
Date: Thu Jun 23 18:04:00 2016
New Revision: 39913

URL: http://svn.gna.org/viewcvs/gnustep?rev=39913&view=rev
Log:
more error checks

Modified:
    libs/sqlclient/trunk/Postgres.m

Modified: libs/sqlclient/trunk/Postgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=39913&r1=39912&r2=39913&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m     (original)
+++ libs/sqlclient/trunk/Postgres.m     Thu Jun 23 18:04:00 2016
@@ -514,7 +514,9 @@
         {
           if (connection != 0)
             {
-              [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+              int       descriptor = PQsocket(connection);
+
+              [runLoop removeEvent: (void*)(uintptr_t)descriptor
                               type: ET_RDESC
                            forMode: NSDefaultRunLoopMode
                                all: YES];
@@ -746,16 +748,28 @@
 #if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
   if (extra != 0 && connection != 0)
     {
+      int       descriptor = PQsocket(connection);
+
       if (nil == runLoop)
         {
           ASSIGN(runLoop, [NSRunLoop currentRunLoop]);
+          if (nil == runLoop)
+            {
+              [NSException raise: NSInternalInconsistencyException
+                format: @"Observer can't be set up ... no runloop in thread"];
+            }
         }
       else if ([NSRunLoop currentRunLoop] != runLoop)
         {
           [NSException raise: NSInternalInconsistencyException
             format: @"Observer added to the same client from another runloop"];
         }
-      [runLoop addEvent: (void*)(uintptr_t)PQsocket(connection)
+      if (descriptor < 0)
+        {
+          [NSException raise: NSInternalInconsistencyException
+            format: @"Observer can't be set up ... bad file descriptor"];
+        }
+      [runLoop addEvent: (void*)(uintptr_t)descriptor
                    type: ET_RDESC
                 watcher: self
                 forMode: NSDefaultRunLoopMode];
@@ -1235,7 +1249,9 @@
     {
       if (connection != 0)
         {
-          [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+          int   descriptor = PQsocket(connection);
+
+          [runLoop removeEvent: (void*)(uintptr_t)descriptor
                           type: ET_RDESC
                        forMode: NSDefaultRunLoopMode
                            all: YES];


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to