fp_toradix_n: make sure too small strings are recognized
If maxlen is too small then we get FP_OKAY as return value but not everything is part of the string. This patch changes it so that the caller learns about this short comming. While at it, drop the doxygen style comment. It is the only of his kind and does no longer match the code. Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
This commit is contained in:
parent
e0fe602802
commit
6fbf2ba87d
@ -9,22 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#include <tfm.h>
|
#include <tfm.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* a: pointer to fp_int representing the input number
|
|
||||||
* str: output buffer
|
|
||||||
* radix: number of character to use for encoding of the number
|
|
||||||
* maxlen: maximum number of the buffer that can be used
|
|
||||||
*
|
|
||||||
* The radix value can be in the range 2 to 64. This function converts number
|
|
||||||
* a into a string str. This function writes at most size bytes (including the
|
|
||||||
* terminating null byte to str. It behaves like snprintf(3) in regard to this.
|
|
||||||
*
|
|
||||||
* Return: If invalid parameter are detected a negative value is returned. On
|
|
||||||
* success the function returns the number of bytes that would be written if
|
|
||||||
* the function had enough space. Thus a return value of maxlen or more means
|
|
||||||
* that the function was not able store all characters and the output is
|
|
||||||
* incomplete.
|
|
||||||
*/
|
|
||||||
int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
|
int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
|
||||||
{
|
{
|
||||||
int digs;
|
int digs;
|
||||||
@ -77,6 +61,8 @@ int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
|
|||||||
/* append a NULL so the string is properly terminated */
|
/* append a NULL so the string is properly terminated */
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
|
|
||||||
|
if (maxlen < 1)
|
||||||
|
return FP_VAL;
|
||||||
return FP_OKAY;
|
return FP_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user