Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson
2025-01-27 11:38:16 -08:00
committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions
@@ -0,0 +1,12 @@
# Regression test for #504:
# Non empty submessage considered empty on FT_POINTER fields with address aligned on 0x100
Import('env', 'malloc_env')
env.NanopbProto(["test.proto"])
test = malloc_env.Program(["test.c",
"test.pb.c",
"$COMMON/pb_encode.o",
"$COMMON/pb_common.o"])
env.RunTest(test)
+78
View File
@@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pb_encode.h>
#include "test.pb.h"
#include "unittests.h"
const char STR[] = "test str";
#define ALIGN 0x100
int main(int argc, char **argv)
{
int status = 0;
uint8_t buffer[512] = {0};
int i;
{
pb_ostream_t ostream;
MyMessage msg = MyMessage_init_zero;
char *pStr, *pStrAligned;
COMMENT("Test for false negatives with pointer value low byte 0x00")
ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
/* copy STR to a malloced 0x100 aligned address */
pStr = malloc(sizeof(STR) + ALIGN);
pStrAligned = (char*)((uintptr_t)(pStr + ALIGN) & ~(ALIGN - 1));
memcpy(pStrAligned, STR, sizeof(STR));
msg.submessage.somestring = pStrAligned;
printf("%p: '%s'\n", msg.submessage.somestring, msg.submessage.somestring);
if (!pb_encode(&ostream, MyMessage_fields, &msg)) {
fprintf(stderr, "Encode failed: %s\n", PB_GET_ERROR(&ostream));
return 1;
}
free(pStr);
msg.submessage.somestring = NULL;
printf("response payload (%d):", (int)ostream.bytes_written);
for (i = 0; i < ostream.bytes_written; i++) {
printf("%02X", buffer[i]);
}
printf("\n");
TEST(ostream.bytes_written != 0);
}
{
pb_ostream_t ostream;
struct {
MyMessage msg;
uint32_t bar;
} msg = {MyMessage_init_zero, 0};
COMMENT("Test for false positives with data after end of struct")
ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
msg.bar = 0xFFFFFFFF;
if (!pb_encode(&ostream, MyMessage_fields, &msg)) {
fprintf(stderr, "Encode failed: %s\n", PB_GET_ERROR(&ostream));
return 1;
}
printf("response payload (%d):", (int)ostream.bytes_written);
for (i = 0; i < ostream.bytes_written; i++) {
printf("%02X", buffer[i]);
}
printf("\n");
TEST(ostream.bytes_written == 0);
}
return status;
}
@@ -0,0 +1,19 @@
syntax = "proto3";
import "nanopb.proto";
message MyMessage
{
SubMessage submessage = 1 [(nanopb).proto3_singular_msgs = true];
}
message SubMessage
{
string somestring = 1 [(nanopb).type = FT_POINTER];
SubMessage2 submsg2 = 2 [(nanopb).type = FT_POINTER];
}
message SubMessage2
{
uint32 foo = 1;
}