aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Bug in example input stream callback's skip count logic #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attempt to decode a message where you will skip a String field (set callback 
to NULL)
2. Run pb_decode() using an input stream whose callback implementation matches 
the implementation in test_decode2.c
3. Observe IO error

What is the expected output? What do you see instead?
I would expect it to skip the field correctly. Instead, the input stream 
callback erroneously returns false because the last decrement on the 'count' 
argument wrapped it around to the largest unsigned value for size_t.

What version of the product are you using? On what operating system?
nanopb 0.1.6
Mac OS X 10.8.2

Please provide any additional information below.

The example input stream callback should decrement the 'count' arg in the body 
of the loop rather than in the loop's test expression. For instance:
  if (buf == NULL)
  {
    /* Skipping data */
    while (count && fgetc(file) != EOF)
      count--;
    return count == 0;
  }

Original issue reported on code.google.com by ke...@circle38.com on 17 Oct 2012 at 7:14

GoogleCodeExporter commented 9 years ago
Ah, good catch.

I wonder if I should remove the skipping part from the stream read callbacks 
altogether. I think it is quite rarely used and it is a bit bothersome to 
implement. Instead, pb_read could just loop itself (and perhaps use a bit 
bigger buffer for performance).

Original comment by Petteri.Aimonen on 17 Oct 2012 at 7:20

GoogleCodeExporter commented 9 years ago
This issue was updated by revision dcab39a41c0a.

Original comment by Petteri.Aimonen on 18 Oct 2012 at 4:49

GoogleCodeExporter commented 9 years ago
Fixed in nanopb-0.1.7

Original comment by Petteri.Aimonen on 12 Nov 2012 at 7:33