On 28 January 2015 at 11:48, Ola Liljedahl <[email protected]> wrote:
>  * @param str    Output buffer
>  * @param len    Size of string length (incl. ending zero)
>  */
> void odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, int len);
>
> Why don't we use size_t for the"len" parameter?

And what happens if the buffer is too small to fit the string
generated from the CPU mask?

There is no way to indicate failure. And I cannot find any recommended
buffer size that would be safe to use.

It is easy to imagine that code written for a machine with low CPU
count might use a small buffer size and succeed but when run on a
machine with high CPU count the output string will be longer than
expected and the operation will fail. (I haven't looked at the
implementation of odp_cpumask_to_str(), it might generate a constant
sized output for all values of the cpumask).

Do we want to return both a failure indication and what buffer size
needs to be specified for successful operation?
snprintf() does this in the following way:
       The  functions  snprintf()  and vsnprintf() do not write more than size
       bytes (including the terminating null byte ('\0')).  If the output  was
       truncated  due  to  this  limit  then the return value is the number of
       characters (excluding the terminating null byte) which would have  been
       written  to the final string if enough space had been available.  Thus,
       a return value of size or more means that  the  output  was  truncated.

Or we return >= 0 on success, the return value is the number of
characters written (including/excluding the terminating null
character) and <0 on failure and the returned value is the minimum
size of the output buffer required for successful operation.

>
> -- Ola

_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to