-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guarantee null-termination for strings. (#2316)
- Loading branch information
Showing
7 changed files
with
107 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2024 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
import expect show * | ||
import io | ||
import monitor | ||
import system.external | ||
|
||
EXTERNAL-ID ::= "toit.io/external-test" | ||
|
||
// Test that strings are 0-terminated on the C side. | ||
main: | ||
client := external.Client.open EXTERNAL-ID | ||
|
||
strings := [ | ||
"", | ||
"foo", | ||
"bar", | ||
"foobar", | ||
"foobar" * 100, | ||
"foobar" * 1000, | ||
"foo"[3..], | ||
"foobar"[3..], | ||
("foobar" * 1000)[1..], | ||
] | ||
strings.do: | str/string | | ||
response/ByteArray := client.request 0 str | ||
expect-equals (str.size + 1) response.size | ||
expect-equals 0 response.last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (C) 2024 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
#include "../../include/toit/toit.h" | ||
|
||
static toit_err_t on_rpc_request(void* user_data, int sender, int function, toit_msg_request_handle_t handle, uint8_t* data, int length) { | ||
if (toit_msg_request_reply(handle, data, length + 1, true) != TOIT_OK) { | ||
printf("unable to reply\n"); | ||
} | ||
return TOIT_OK; | ||
} | ||
|
||
static void __attribute__((constructor)) init() { | ||
printf("registering external handler 1\n"); | ||
toit_msg_cbs_t cbs = TOIT_MSG_EMPTY_CBS(); | ||
cbs.on_rpc_request = on_rpc_request; | ||
toit_msg_add_handler("toit.io/external-test", NULL, cbs); | ||
} |