Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Development mailing list

Subject: Re: [hwloc-devel] [hwloc-svn] svn:hwloc r2083
From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2010-05-07 11:29:27


Question about this; I didn't care much before, but thinking about this more, I think I do care a bit...

The OSX man page for snprintf says:

     These functions return the number of characters printed (not including
     the trailing `\0' used to end output to strings) or a negative value if
     an output error occurs, except for snprintf() and vsnprintf(), which
     return the number of characters that would have been printed if the n
     were unlimited (again, not including the final `\0').

So if hwloc_snprintf() returns 0, how do you know if you got a zero-length string or an error? I would think that returning -1 for errors is better because then you know that the string is invalid and should not attempt to be printed. Whereas 0 always means "a valid zero-length string".

I think callers should check for whatever we document they should check for -- hwloc_snprintf() is "new", so they (should) check for whatever we put in doxygen.

My $0.04...

On May 7, 2010, at 8:55 AM, <sthibaul_at_[hidden]> <sthibaul_at_[hidden]> wrote:

> Author: sthibaul
> Date: 2010-05-07 08:55:18 EDT (Fri, 07 May 2010)
> New Revision: 2083
> URL: https://svn.open-mpi.org/trac/hwloc/changeset/2083
>
> Log:
> make hwloc_snprintf return 0 instead of -1, which callers may not check for.
> Text files modified:
> trunk/src/misc.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> Modified: trunk/src/misc.c
> ==============================================================================
> --- trunk/src/misc.c (original)
> +++ trunk/src/misc.c 2010-05-07 08:55:18 EDT (Fri, 07 May 2010)
> @@ -40,7 +40,8 @@
> size *= 2;
> str = malloc(size);
> if (NULL == str) {
> - return -1;
> + /* Couldn't allocate?! Let's return the least surprising value. */
> + return 0;
> }
> va_start(ap, format);
> errno = 0;
> _______________________________________________
> hwloc-svn mailing list
> hwloc-svn_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/hwloc-svn
>

-- 
Jeff Squyres
jsquyres_at_[hidden]
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/