Browse Source

Properly propagate errors when creating a DataView (fixes #1476)

The C++ code already threw an exception when creating a DataView with size 0, but the corresponding lua wrapper ignored it. Now it's correctly turned into a lua error.
Bart van Strien 6 years ago
parent
commit
3d64ad0a3e
1 changed files with 2 additions and 1 deletions
  1. 2 1
      src/modules/data/wrap_DataModule.cpp

+ 2 - 1
src/modules/data/wrap_DataModule.cpp

@@ -62,7 +62,8 @@ int w_newDataView(lua_State *L)
 	if (offset < 0 || size < 0)
 	if (offset < 0 || size < 0)
 		return luaL_error(L, "DataView offset and size must not be negative.");
 		return luaL_error(L, "DataView offset and size must not be negative.");
 
 
-	DataView *d = instance()->newDataView(data, (size_t) offset, (size_t) size);
+	DataView *d;
+	luax_catchexcept(L, [&]() { d = instance()->newDataView(data, (size_t) offset, (size_t) size); });
 	luax_pushtype(L, d);
 	luax_pushtype(L, d);
 	d->release();
 	d->release();