fflush stdin in actsync

Julien ÉLIE julien at trigofacile.com
Sun Apr 3 13:47:16 UTC 2016


Hi Richard,

>> In backends/actsync.c, we use "fflush(stdin)" that has undefined
>> behaviour (portability issue).
>> Has someone ever encountered an issue with actsync because of that?
>>
>> Is it worth trying to fix it?  (using scanf for instance and discarding
>> output)
>
> It's undefined in C99 but has defined behavior in SUS:
>
> For a stream open for reading, if the file is not already at EOF, and
> the file is one capable of seeking, the file offset of the underlying
> open file description shall be set to the file position of the stream,
> and any characters pushed back onto the stream by ungetc() or ungetwc()
> that have not subsequently been read from the stream shall be discarded
> (without further changing the file offset)
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html
>
> So it depends what the portability goal is.

Thanks for your answer.
I was having a look at the result of cppcheck against INN source code. 
One of the errors found is in backends/actsync.c:
     (error) fflush() called on input stream 'stdin' results in 
undefined behaviour.

That's why I wonder whether it would be worth fixing.
As POSIX 2013 now defines it (according to the page you quoted), maybe 
we could keep it as-is.

-- 
Julien ÉLIE

« The hardest thing is to go to sleep at night, when there are so many
   urgent things needing to be done.  A huge gap exists between what we
   know is possible with today's machines and what we have so far been
   able to finish. »  (Donald Knuth)


More information about the inn-workers mailing list