__sinit - NULL pointers from __sfp with _REENT_SMALL

Matt Lee reachmatt.lee@gmail.com
Wed Sep 5 00:26:00 GMT 2007


I have a suggestion for a minor enhancement.

_sinit does not seem to check for NULL pointers when assigning file
structures using __sfp under _REENT_SMALL.

findfp.c:

#ifndef _REENT_SMALL
  s->__sglue._niobs = 3;
  s->__sglue._iobs = &s->__sf[0];
#else
  s->__sglue._niobs = 0;
  s->__sglue._iobs = NULL;
  s->_stdin = __sfp(s);
  s->_stdout = __sfp(s);
  s->_stderr = __sfp(s);
#endif

std (s->_stdin,  __SRD, 0, s);

This will happen when the heap size is too small or even zero. This is
not uncommon in some embedded systems. While the user eventually does
need to allocate more heap space, he will not get a graceful failure
when there is not enough.

__sinit does not return any status and stdio will require rework to
propagate the error back to callers. Any suggestions on the best way
to handle this error in my architecture? Are assertions accepted
practice to trap such situations?

Lastly, should I file a bug report?

-- 
thanks,
Matt



More information about the Newlib mailing list