And though you implied it, I didn't see you explicitly say, so I will...
Code that does this violates the standard, so this constitutes a bug in
your code. And no, compilers are not required to catch that bug; it is
of a kind where you can just get silent corruption of results.
As Gordon said, 1P edit descriptors can have symptoms like this. My
first reaction was to look for such a 1P because it sounds so much like
that kind of problem; those can be darn confusing - a stronger word than
"darn" might even be more appropriate. Might possibly still be the
problem, though I didn't see such a 1P. The so-called "recursive I/O"
(aka I/O while I/O is active) is a bug in the code in any case.
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain