mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 07:46:16 +08:00
libc/stdlib: Error Fix
1.Fix an error in mkstemp() the could result in an infinite loop.
2.Fix for wrong output in some cases.
For Example:
1) input: "FILEXX"
output: "FILE00" and repeats same output for further invocations of mkstemp().
But, the ouput has to be FILE01, FILE02, ...., FILEZZ.
2)input: "FILEXXXXXX"
output: "FILE100000", for next invocation "FILE200000" and so on
But it's good, if the ouput goes like FILE000001, FILE000002, ..., FILE000101, ...
Signed-off-by: Lokesh B V <lokeshbv333@gmail.com>
This commit is contained in:
@@ -125,7 +125,7 @@ static void incr_base62(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_XS; i++)
|
||||
for (i = MAX_XS - 1; i >= 0; i--)
|
||||
{
|
||||
if (g_base62[i] < MAX_LOWERCASE)
|
||||
{
|
||||
@@ -168,11 +168,8 @@ static void get_base62(FAR uint8_t *ptr)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void copy_base62(FAR char *dest, int len)
|
||||
static void copy_base62(FAR const uint8_t *src, FAR char *dest, int len)
|
||||
{
|
||||
FAR const uint8_t *src;
|
||||
|
||||
src = g_base62;
|
||||
if (len < MAX_XS)
|
||||
{
|
||||
src += MAX_XS - len;
|
||||
@@ -264,11 +261,11 @@ int mkstemp(FAR char *path_template)
|
||||
{
|
||||
/* Sample and increment the base62 counter */
|
||||
|
||||
get_base62(base62);
|
||||
get_base62(base62);
|
||||
|
||||
/* Form the candidate file name */
|
||||
|
||||
copy_base62(xptr, xlen);
|
||||
copy_base62(base62, xptr, xlen);
|
||||
|
||||
/* Attempt to open the candidate file -- creating it exclusively
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user