]> sigrok.org Git - libserialport.git/blobdiff - serialport.c
Check return value of GetOverlappedResult().
[libserialport.git] / serialport.c
index 45f9773bd56020dfbc9fba2453fbb0f3b3b0b73e..b7dd66a3bfad1220d319a75fb141cae588ee47e7 100644 (file)
@@ -173,7 +173,11 @@ void (*sp_debug_handler)(const char *format, ...) = sp_default_debug_handler;
 #define RETURN_OK() RETURN_CODE(SP_OK);
 #define RETURN_ERROR(err, msg) do { DEBUG_ERROR(err, msg); return err; } while (0)
 #define RETURN_FAIL(msg) do { DEBUG_FAIL(msg); return SP_ERR_FAIL; } while (0)
-#define RETURN_VALUE(fmt, x) do { DEBUG("%s returning " fmt, __func__, x); return x; } while (0)
+#define RETURN_VALUE(fmt, x) do { \
+       typeof(x) _x = x; \
+       DEBUG("%s returning " fmt, __func__, _x); \
+       return _x; \
+} while (0)
 #define SET_ERROR(val, err, msg) do { DEBUG_ERROR(err, msg); val = err; } while (0)
 #define SET_FAIL(val, msg) do { DEBUG_FAIL(msg); val = SP_ERR_FAIL; } while (0)
 #define TRACE(fmt, ...) DEBUG("%s(" fmt ") called", __func__, ##__VA_ARGS__)
@@ -1151,7 +1155,8 @@ enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count
                RETURN_FAIL("ReadFile() failed");
 
        /* Get number of bytes read. */
-       GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE);
+       if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE) == 0)
+               RETURN_FAIL("GetOverlappedResult() failed");
 
        RETURN_VALUE("%d", bytes_read);
 #else