Skip to content

Commit ebf1ab5

Browse files
Zhangshoukuianchao
authored andcommitted
lib_get_pathbuffer: Modify size to the maximum value of PATH_MAX and CONFIG_LINE_MAX
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
1 parent f8377f8 commit ebf1ab5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

libs/libc/misc/lib_pathbuffer.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@
3535
* Pre-processor definitions
3636
****************************************************************************/
3737

38+
#if CONFIG_PATH_MAX > CONFIG_LINE_MAX
39+
# define PATH_MAX_SIZE CONFIG_PATH_MAX
40+
#else
41+
# define PATH_MAX_SIZE CONFIG_LINE_MAX
42+
#endif
43+
3844
/****************************************************************************
3945
* Private Types
4046
****************************************************************************/
4147

4248
struct pathbuffer_s
4349
{
4450
atomic_t free_bitmap; /* Bitmap of free buffer */
45-
char buffer[CONFIG_LIBC_PATHBUFFER_MAX][PATH_MAX];
51+
char buffer[CONFIG_LIBC_PATHBUFFER_MAX][PATH_MAX_SIZE];
4652
};
4753

4854
/****************************************************************************
@@ -69,7 +75,7 @@ static struct pathbuffer_s g_pathbuffer =
6975
* The lib_get_pathbuffer() function returns a pointer to a temporary
7076
* buffer. The buffer is allocated from a pool of pre-allocated buffers
7177
* and if the pool is exhausted, a new buffer is allocated through
72-
* kmm_malloc(). The size of the buffer is PATH_MAX, and must freed by
78+
* kmm_malloc(). The size of the buffer is PATH_MAX_SIZE, and must freed by
7379
* calling lib_put_pathbuffer().
7480
*
7581
* Returned Value:
@@ -103,7 +109,7 @@ FAR char *lib_get_pathbuffer(void)
103109
*/
104110

105111
#ifdef CONFIG_LIBC_PATHBUFFER_MALLOC
106-
return lib_malloc(PATH_MAX);
112+
return lib_malloc(PATH_MAX_SIZE);
107113
#else
108114
return NULL;
109115
#endif
@@ -125,7 +131,7 @@ FAR char *lib_get_pathbuffer(void)
125131

126132
void lib_put_pathbuffer(FAR char *buffer)
127133
{
128-
int index = (buffer - &g_pathbuffer.buffer[0][0]) / PATH_MAX;
134+
int index = (buffer - &g_pathbuffer.buffer[0][0]) / PATH_MAX_SIZE;
129135
if (index >= 0 && index < CONFIG_LIBC_PATHBUFFER_MAX)
130136
{
131137
DEBUGASSERT((atomic_read(&g_pathbuffer.free_bitmap) &

0 commit comments

Comments
 (0)