Skip to content

Commit 40c25b9

Browse files
pdgendtMaureenHelm
authored andcommitted
samples: modules: nanopb: fix encode buffer size
A bug was introduced when encoding/decoding moved to separate functions where sizeof no longer had the correct argument. The size of the encode buffer is passed to the encode function. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 089f907 commit 40c25b9

File tree

1 file changed

+3
-3
lines changed
  • samples/modules/nanopb/src

1 file changed

+3
-3
lines changed

samples/modules/nanopb/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <pb_decode.h>
1313
#include "src/simple.pb.h"
1414

15-
bool encode_message(uint8_t *buffer, size_t *message_length)
15+
bool encode_message(uint8_t *buffer, size_t buffer_size, size_t *message_length)
1616
{
1717
bool status;
1818

@@ -26,7 +26,7 @@ bool encode_message(uint8_t *buffer, size_t *message_length)
2626
SimpleMessage message = SimpleMessage_init_zero;
2727

2828
/* Create a stream that will write to our buffer. */
29-
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
29+
pb_ostream_t stream = pb_ostream_from_buffer(buffer, buffer_size);
3030

3131
/* Fill in the lucky number */
3232
message.lucky_number = 13;
@@ -73,7 +73,7 @@ void main(void)
7373
size_t message_length;
7474

7575
/* Encode our message */
76-
if (!encode_message(buffer, &message_length)) {
76+
if (!encode_message(buffer, sizeof(buffer), &message_length)) {
7777
return;
7878
}
7979

0 commit comments

Comments
 (0)