Fix compiler warning with PB_BUFFER_ONLY (#717)
I also took the opportunity to get rid of a potential undefined behavior.
Now the marker value used is a valid const int pointer.
diff --git a/pb_encode.c b/pb_encode.c
index f5f1676..2ad9925 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -65,7 +65,11 @@
{
pb_ostream_t stream;
#ifdef PB_BUFFER_ONLY
- stream.callback = (void*)1; /* Just a marker value */
+ /* In PB_BUFFER_ONLY configuration the callback pointer is just int*.
+ * NULL pointer marks a sizing field, so put a non-NULL value to mark a buffer stream.
+ */
+ static const int marker;
+ stream.callback = ▮
#else
stream.callback = &buf_write;
#endif
diff --git a/pb_encode.h b/pb_encode.h
index 9cff22a..8913683 100644
--- a/pb_encode.h
+++ b/pb_encode.h
@@ -33,7 +33,7 @@
* Also, NULL pointer marks a 'sizing stream' that does not
* write anything.
*/
- int *callback;
+ const int *callback;
#else
bool (*callback)(pb_ostream_t *stream, const pb_byte_t *buf, size_t count);
#endif