Skip to content

Commit

Permalink
Merge pull request #5 from wrv/main
Browse files Browse the repository at this point in the history
Add release_assert and .gitignore for builds
  • Loading branch information
shravanrn authored Nov 17, 2023
2 parents da5fa7a + b7d277a commit 309e702
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/chapters/examples/noop-hello-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
7 changes: 3 additions & 4 deletions src/chapters/examples/noop-hello-example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <rlbox/rlbox.hpp>
#include <rlbox/rlbox_noop_sandbox.hpp>

#define release_assert(cond, msg) if (!(cond)) { fputs(msg, stderr); abort(); }

#include "mylib.h"

using namespace std;
Expand All @@ -33,9 +35,6 @@ int main(int argc, char const *argv[]) {

// ANCHOR: add
// call the add function and check the result:
auto val = sandbox.invoke_sandbox_function(add, 3, 4);
printf("Adding... 3+4 = %d\n", val);

auto ok = sandbox.invoke_sandbox_function(add, 3, 4)
.copy_and_verify([](unsigned ret){
printf("Adding... 3+4 = %d\n", ret);
Expand Down Expand Up @@ -76,7 +75,7 @@ int main(int argc, char const *argv[]) {
void hello_cb(rlbox_sandbox_mylib& _, tainted_mylib<const char*> str) {
auto checked_string =
str.copy_and_verify_string([](unique_ptr<char[]> val) {
assert(val != nullptr && strlen(val.get()) < 1024);
release_assert(val != nullptr && strlen(val.get()) < 1024, "val is null or greater than 1024\n");
return move(val);
});
printf("hello_cb: %s\n", checked_string.get());
Expand Down
3 changes: 3 additions & 0 deletions src/chapters/examples/wasm-hello-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
myapp
mylib.wasm*
wasm*
3 changes: 2 additions & 1 deletion src/chapters/examples/wasm-hello-example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "rlbox.hpp"
#include "rlbox_wasm2c_sandbox.hpp"

#define release_assert(cond, msg) if (!(cond)) { fputs(msg, stderr); abort(); }

using namespace std;
using namespace rlbox;
Expand Down Expand Up @@ -78,7 +79,7 @@ int main(int argc, char const *argv[]) {
void hello_cb(rlbox_sandbox_mylib& _, tainted_mylib<const char*> str) {
auto checked_string =
str.copy_and_verify_string([](unique_ptr<char[]> val) {
assert(val != nullptr && strlen(val.get()) < 1024);
release_assert(val != nullptr && strlen(val.get()) < 1024);
return move(val);
});
printf("hello_cb: %s\n", checked_string.get());
Expand Down
2 changes: 1 addition & 1 deletion src/chapters/noop-sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ string we need to verify it. To do this, we use the string verification function
```cpp
str.copy_and_verify_string([](unique_ptr<char[]> val) {
assert(val != nullptr && strlen(val.get()) < 1024);
release_assert(val != nullptr && strlen(val.get()) < 1024, "val is null or greater than 1024\n");
return move(val);
});
```
Expand Down

0 comments on commit 309e702

Please sign in to comment.