LCOV - code coverage report
Current view: top level - regression/GHSA-gcx3-7m76-287p - test.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 16 87.5 %
Date: 2023-02-14 20:10:26 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include <pb_decode.h>
       2             : #include <stdio.h>
       3             : #include <string.h>
       4             : #include <assert.h>
       5             : #include "test_helpers.h"
       6             : #include "test.pb.h"
       7             : 
       8         114 : bool stream_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
       9             : {
      10         114 :     FILE *file = (FILE*)stream->state;
      11         114 :     size_t len = fread(buf, 1, count, file);
      12             :     
      13         114 :     if (len == count)
      14             :     {
      15         114 :         return true;
      16             :     }
      17             :     else
      18             :     {
      19           0 :         stream->bytes_left = 0;
      20           0 :         return false;
      21             :     }
      22             : }
      23             : 
      24           1 : int main()
      25             : {
      26           1 :     pb_istream_t stream = {&stream_callback, NULL, SIZE_MAX};
      27           1 :     MyMessage msg = MyMessage_init_default;
      28             :     bool status;
      29           1 :     stream.state = stdin;
      30             :     SET_BINARY_MODE(stdin);
      31             : 
      32           1 :     set_max_alloc_bytes(512);
      33             : 
      34           1 :     status = pb_decode(&stream, MyMessage_fields, &msg);
      35           1 :     assert(!status);
      36           1 :     assert(strcmp(stream.errmsg, "realloc failed") == 0);
      37           1 :     return 0;
      38             : }
      39             : 

Generated by: LCOV version 1.14