summaryrefslogtreecommitdiffstats
path: root/pb_encode.c
diff options
context:
space:
mode:
Diffstat (limited to 'pb_encode.c')
-rw-r--r--pb_encode.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/pb_encode.c b/pb_encode.c
index 48a3c950..0e048ac6 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -461,8 +461,16 @@ bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, con
bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src)
{
- UNUSED(field);
- return pb_encode_string(stream, (const uint8_t*)src, strlen((const char*)src));
+ /* strnlen() is not always available, so just use a for-loop */
+ size_t size = 0;
+ const char *p = (const char*)src;
+ while (size < field->data_size && *p != '\0')
+ {
+ size++;
+ p++;
+ }
+
+ return pb_encode_string(stream, (const uint8_t*)src, size);
}
bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void *src)