summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-09-24 20:32:29 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-09-24 20:32:54 +0300
commit5e4356ef4b5be9995f2038ba294e4c538167ac01 (patch)
tree1f47c353c973370affdba44dfb6e105c4b82c5c1 /examples
parent6db720aa7597d1830016ad3f697ddade65d481bf (diff)
Add initialization to examples/simple
Diffstat (limited to 'examples')
-rw-r--r--examples/cmake_simple/simple.c9
-rw-r--r--examples/simple/simple.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/examples/cmake_simple/simple.c b/examples/cmake_simple/simple.c
index 31272301..1f6b1373 100644
--- a/examples/cmake_simple/simple.c
+++ b/examples/cmake_simple/simple.c
@@ -15,8 +15,11 @@ int main()
/* Allocate space on the stack to store the message data.
*
* Nanopb generates simple struct definitions for all the messages.
- * - check out the contents of simple.pb.h! */
- SimpleMessage message;
+ * - check out the contents of simple.pb.h!
+ * It is a good idea to always initialize your structures
+ * so that you do not have garbage data from RAM in there.
+ */
+ SimpleMessage message = SimpleMessage_init_zero;
/* Create a stream that will write to our buffer. */
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
@@ -44,7 +47,7 @@ int main()
{
/* Allocate space for the decoded message. */
- SimpleMessage message;
+ SimpleMessage message = SimpleMessage_init_zero;
/* Create a stream that reads from the buffer. */
pb_istream_t stream = pb_istream_from_buffer(buffer, message_length);
diff --git a/examples/simple/simple.c b/examples/simple/simple.c
index 31272301..1f6b1373 100644
--- a/examples/simple/simple.c
+++ b/examples/simple/simple.c
@@ -15,8 +15,11 @@ int main()
/* Allocate space on the stack to store the message data.
*
* Nanopb generates simple struct definitions for all the messages.
- * - check out the contents of simple.pb.h! */
- SimpleMessage message;
+ * - check out the contents of simple.pb.h!
+ * It is a good idea to always initialize your structures
+ * so that you do not have garbage data from RAM in there.
+ */
+ SimpleMessage message = SimpleMessage_init_zero;
/* Create a stream that will write to our buffer. */
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
@@ -44,7 +47,7 @@ int main()
{
/* Allocate space for the decoded message. */
- SimpleMessage message;
+ SimpleMessage message = SimpleMessage_init_zero;
/* Create a stream that reads from the buffer. */
pb_istream_t stream = pb_istream_from_buffer(buffer, message_length);