Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 2013 17:18:33 -0800
From:      John-Mark Gurney <jmg@funkthat.com>
To:        freebsd-arch@FreeBSD.org
Subject:   return value from humanize_number
Message-ID:  <20130302011833.GM55866@funkthat.com>

next in thread | raw e-mail | index | archive | help
I picked up the work to fix up humanize_number, but now I have a problem..
Currently, if a number is too big to fit, we write what we can, and
return the number of bytes we would of written if len allowed us..

The problem is that isn't what the man page says:
     The humanize_number() function returns the number of characters stored in
     buf (excluding the terminating NUL) upon success, or -1 upon failure.  If
     HN_GETSCALE is specified, the prefix index number will be returned
     instead.

It can return 21 even when len is 4, and we only store 3 characters in
buf...

So, the question is, do we fix the code to return an error if we
attempt to write more than len - 1 characters, or do we change the
man page to say that we return what we would like to have written, but
only write out what we can (snprintf style, which is what we use)...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130302011833.GM55866>