On Fri, Feb 1, 2019 at 10:00 AM Jeffrey M. Rose <jeffreymr...@yahoo.com>
wrote:

> I wrote a custom GRC block called gensup_ff that receives a stream of “0”
> and “1” characters and is supposed to output a stream of of only the “1”
> characters it received.
>
> In my flowgraph, I have a file sink that sinks these “1” characters into a
> file.
>
> However, when I open the file, not only does it have the “1” characters
> but it has thousands of unwanted NULL characters, too.
>

I'm not familiar with writing blocks using general_work in detail, but I
can see one definite problem:

        if (in[i] == '1')
        {
           one_count++;
           out[i] = in[i];
        }

Here you are copying your '1's into the i-th position of out, not the next
one. So this accounts for the extra characters — they may be the
uninitialized part of your output buffer that you did not write. Instead,
you need to keep track of the next index into the output buffer you want to
write into. In your particular case, that's the same as one_count, if you
copy before incrementing it.

Additionally, you could be writing past the end of the output buffer
(potential memory corruption), whose size is specified by the noutput_items
parameter (not ninput_items). In principle, you should stop processing
input as soon as you have written noutput_items items (and tell GR that you
only consumed however many items that was); it may be that with the
forecast() you have, the output buffer will always be that big; I don't
know.
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to