Private
Public Access
2
0

mraajs.i: add buffer checks to python write() typemaps in Spi & I2c

Previously anything passed to an I2c::write() or Spi::write() function in
node.js that wasn't a node::Buffer or an object would likely cause a segfault
later on during future calls. This change calls node::Buffer::HasInstance(obj)
to make sure the buffer is valid prior to grabbing it's data

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-05-20 11:16:15 +01:00
parent f4d67b5f53
commit 55533ed8c1

View File

@@ -11,11 +11,17 @@
%}
%typemap(in) (const uint8_t *data, int length) {
if (!node::Buffer::HasInstance($input)) {
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
}
$1 = (uint8_t*) node::Buffer::Data($input);
$2 = node::Buffer::Length($input);
}
%typemap(in) (uint8_t *txBuf, int length) {
if (!node::Buffer::HasInstance($input)) {
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
}
$1 = (uint8_t*) node::Buffer::Data($input);
$2 = node::Buffer::Length($input);
}