NOAA-EMC / NCEPLIBS-bufr

The NCEPLIBS-bufr library contains routines and utilites for working with the WMO BUFR format.
Other
44 stars 19 forks source link

subroutine numtbd() segfaults if called before file is opened #468

Closed edwardhartnett closed 8 months ago

edwardhartnett commented 1 year ago

Similar to #395, when stseq() is called before any file is opened, numtbd() causes a segfault.

This should not just result in a warning, we need to do something sensible. Perhaps calling the initialziion function would be best...

jbathegit commented 1 year ago

Again, this is another one of those routines that really isn't ever expected to be called prior to openbf having been called. If you don't like the warning approach that we've previously used in closbf and status, then the only other alternative I see in such cases would be to do a direct call to openbf with the 2nd argument as 'QUIET' inside of this routine, and which in turn would allocate all of the internal arrays.

Personally, I like the warning approach because it gives the user an indication that they're doing something that's not really kosher, rather than just silently "fixing" the problem internally and in which case they're never any the wiser. Either way, and as noted previously, there are likely similar bugaboos lurking in a number of other routines as well, since many of them (like this one) weren't ever expected to be called directly by a user application program but rather only internally within the library.

edwardhartnett commented 8 months ago

I'm going to close this based on the fact that this is not part of the user API, but an internal function.

As long as we can agree that no function that is part of the user API should segfault. Instead it should always check its inputs and error out sensibly if something is wrong.