Fixes spacetelescope/PyFITS#71

This is a fix I merged in from PyFITS (see spacetelescope/PyFITS#71).  I've already tested this on the PyFITS end, so if the tests pass here it should be merged in.  It's a bug that can lead to writing corrupt data which is always bad.