aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2017-10-23 12:07:55 +0200
committerDan Gudmundsson <[email protected]>2017-10-23 12:07:55 +0200
commitfcbace8f04c741652820d9f91c6de7b49c92c1d9 (patch)
tree0e25d4ca3c4288c41cb92d09adf9eed7a7dff7fd /lib
parentfaddc82d3c8c25fbddb1074d511582b8ac020c38 (diff)
parent823cab1ec24af0235195b14ee66a8642e4913699 (diff)
downloadotp-fcbace8f04c741652820d9f91c6de7b49c92c1d9.tar.gz
otp-fcbace8f04c741652820d9f91c6de7b49c92c1d9.tar.bz2
otp-fcbace8f04c741652820d9f91c6de7b49c92c1d9.zip
Merge branch 'dgud/wx/fix-empty-binaries/OTP-14688' into maint
* dgud/wx/fix-empty-binaries/OTP-14688: Correct io_vec handling
Diffstat (limited to 'lib')
-rw-r--r--lib/wx/c_src/wxe_driver.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/wx/c_src/wxe_driver.c b/lib/wx/c_src/wxe_driver.c
index 5da71818e5..26ae3564e7 100644
--- a/lib/wx/c_src/wxe_driver.c
+++ b/lib/wx/c_src/wxe_driver.c
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <fcntl.h>
+#include <assert.h>
#include "wxe_driver.h"
#define TEMP_BINARY_SIZE 512
@@ -234,13 +235,21 @@ standard_outputv(ErlDrvData drv_data, ErlIOVec* ev)
sd->max_bins = max;
}
- if(ev->vsize == 2) {
- binref->base = ev->iov[1].iov_base;
- binref->size = ev->iov[1].iov_len;
- binref->from = driver_caller(sd->port_handle);
- bin = ev->binv[1];
- driver_binary_inc_refc(bin); /* Otherwise it could get deallocated */
- binref->bin = bin;
+ if(ev->size > 0) {
+ assert(ev->vsize == 2 && ev->iov[0].iov_len == 0
+ && "erts changed how the ErlIOVec is structured for outputv");
+ binref->from = driver_caller(sd->port_handle);
+ binref->size = ev->iov[1].iov_len;
+ if(ev->binv[1]) {
+ binref->base = ev->iov[1].iov_base;
+ bin = ev->binv[1];
+ driver_binary_inc_refc(bin); /* Otherwise it could get deallocated */
+ } else {
+ bin = driver_alloc_binary(ev->iov[1].iov_len);
+ memcpy(bin->orig_bytes, ev->iov[1].iov_base, ev->iov[1].iov_len);
+ binref->base = bin->orig_bytes;
+ }
+ binref->bin = bin;
} else { /* Empty binary (becomes NULL) */
binref->base = NULL;
binref->size = 0;