QNX 6.2NC
In the resource manager io_read() below it works fine if I leave the “int i”
declaration at the start, which is an unused variable, but exits (i.e.
returns -1 to the read() call) if the declaration is removed. The code is
basically an exact copy of what is in the docs/Rob Krten’s book but I cannot
see what I have done wrong. I suspect that the output_data pointer is being
used to overwrite the stack variables and the “int i” provides 4 bytes of
protection. Can anyone tell me what my newbie mistake is?
//**************************************************************************
int io_read(resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
{
int nleft;
int nbytes;
int nparts;
int status;
int i;
char *output_data;
if ((status = iofunc_read_verify(ctp, msg, ocb, NULL)) != EOK)
return status;
if (msg->i.xtype & _IO_XTYPE_MASK != _IO_XTYPE_NONE)
return(ENOSYS);
// Fill buffer with data
sprintf(output_data, “%f\n”, (float) data);
ocb->attr->nbytes = strlen(output_data)+1;
nleft = ocb->attr->nbytes - ocb->offset;
nbytes = min (msg->i.nbytes, nleft);
if (nbytes > 0)
{
SETIOV (ctp->iov, output_data + ocb->offset, nbytes);
_IO_SET_READ_NBYTES (ctp, nbytes);
if (nbytes < strlen(output_data))
ocb->offset += nbytes;
else
ocb->offset = 0;
nparts = 1;
}
else
{
_IO_SET_READ_NBYTES (ctp, 0);
nparts = 0;
}
if (msg->i.nbytes > 0)
ocb->attr->flags |= IOFUNC_ATTR_ATIME;
return (_RESMGR_NPARTS (nparts));
}
//**************************************************************************
\
Paul.