[vlc-devel] [PATCH] linux/dirs: fix condition checks

Rémi Denis-Courmont remi at remlab.net
Thu Nov 1 15:26:23 CET 2018


Le jeudi 1 novembre 2018, 04:59:55 EET Zhao Zhili a écrit :
> ---
>  src/linux/dirs.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/linux/dirs.c b/src/linux/dirs.c
> index f5dbdaa..b8ad5b9 100644
> --- a/src/linux/dirs.c
> +++ b/src/linux/dirs.c
> @@ -60,10 +60,11 @@ static char *config_GetLibDirRaw(void)
>          if (dir == NULL)
>              continue;
> 
> -        char *file = strrchr (line, '/');
> -        if (end == NULL)
> -            continue;
> -        *file = '\0';
> +        char *file = strrchr (dir, '/');
> +        if (likely(file != dir))
> +            *file = '\0';
> +        else /* install libs at the root directory, unlikely */
> +            *(file + 1) = '\0';

The existing callers expect the string to terminate without a slash. 
Admittedly, that is bad practice, or arguably even a bug, in the case of root 
directory.

But if we are going to include the final  slash in the root case, we should 
include it in all cases. And in any case case, the call sites must be fixed 
accordingly.

-- 
Rémi Denis-Courmont




More information about the vlc-devel mailing list