[Openais] SaNameT to char* implementation.

Steven Dake sdake at redhat.com
Tue Aug 22 08:44:46 PDT 2006


On Tue, 2006-08-22 at 19:54 +0530, Manikandan Pattabiraman wrote:
> Hello,
> 
> > Thank you for the notification.  The attached patch is the correct
> > solution for the problem.
> 
> Thanks for the quick fix.
> In the fix, there is a static buffer that is returned from the method.
> That buffer will be overwritten in the subsequent calls to getSaNameT
> and if the returned pointer is stored and used, it will cause
> confusions, also in threaded contexts non-reentrant methods are always
> a problem.
> 
> we can allocate a new buffer and return but it is the callers
> responsibility to free the memory. This will work perfectly but will
> involve lots of code change and testing too.
> 
> please correct me if am wrong.
> 

Yes you are correct, although the buffer is "static" meaning that the
buffer is safe until the next call of getSaNameT.  I don't want to go
changing all of the callers to pass a separate buffer, just as I didn't
want to do this for totemip_print.

If we have a condition where reentrancy is an issue, such as a threaded
context, we can add a _r version which takes an input buffer from the
caller.

However, changing every usage of getSaNameT and get_mar_name_t to match
this calling style seems a little over the top to me unless absolutely
necessary (threaded context).

Regards
-steve

> Thanks
> Mani.,
> 
> 
> >
> > Regards
> > -steve
> >
> > On Mon, 2006-08-21 at 23:26 +0530, Manikandan Pattabiraman wrote:
> > > All,
> > >
> > > While I was browsing through openais sources, came across this piece of code.
> > >
> > > " return ((char *)name->value)" will return a string, which may not be
> > > null terminated (if len is 256),
> > > causing many problems.
> > >
> > >
> > > Any suggestions/comments?
> > >
> > > Thanks
> > > Mani.
> > >
> > >
> > > ================================
> > > char *getSaNameT (SaNameT *name)
> > > {
> > > #if 0
> > >       static char ret_name[300];
> > >
> > >       memset (ret_name, 0, sizeof (ret_name));
> > >
> > >       if (name->length > 299) {
> > >               memcpy (ret_name, name->value, 299);
> > >       } else {
> > >
> > >               memcpy (ret_name, name->value, name->length);
> > >       }
> > >       return (ret_name);
> > > #endif
> > > // TODO
> > >       return ((char *)name->value);
> > >
> > > }
> > > ===============================
> > > _______________________________________________
> > > Openais mailing list
> > > Openais at lists.osdl.org
> > > https://lists.osdl.org/mailman/listinfo/openais
> >
> >
> >




More information about the Openais mailing list