[vlc-devel] [PATCH 3/3] playlist soring1
Rémi Denis-Courmont
remi at remlab.net
Thu Mar 27 19:23:37 CET 2014
Le jeudi 27 mars 2014, 23:30:09 Rashmi Raghunandan a écrit :
> ---
> src/playlist/sort.c | 55
> ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52
> insertions(+), 3 deletions(-)
>
> diff --git a/src/playlist/sort.c b/src/playlist/sort.c
> index 2b91a90..0469da9 100644
> --- a/src/playlist/sort.c
> +++ b/src/playlist/sort.c
> @@ -32,6 +32,55 @@
> #include "vlc_playlist.h"
> #include "playlist_internal.h"
>
> +int meta_newcmp(const char *,const char *);
> +int meta_digcheck(char);
> +
> +/*method to check if character is digit*/
> +int meta_digcheck(char num)
> +{
> + if(num>='0' && num <= '9')
> + return 1;
> + else
> + return 0;
> +}
This is called isdigit().
> +
> +
> +/*overriding strcasecmp with method to check numbers amd sort lexicallly*/
> +int meta_newcmp( const char *psz_s1, const char *psz_s2 )
> +{
> +
> + while (*psz_s1 == *psz_s2)
> + {
> + if ( *psz_s1 == '\0' )
> + return 0;
> + psz_s1++;
> + psz_s2++;
> + }
> +
> + if(meta_digcheck(*psz_s1))
> + {
> +
> + char t1[1000],t2[1000];
> + int i=0,j=0;
> + while(*psz_s1!='\0' && meta_digcheck(*psz_s1))
> + {
> + t1[i]=*psz_s1;
> + psz_s1++;
> + i++;
> + }
> + while(*psz_s2!='\0' && meta_digcheck(*psz_s2))
> + {
> + t2[j]=*psz_s2;
> + psz_s2++;
> + j++;
> + }
This can trivially overflow.
> +
> + return atoi(t1)<atoi(t2)? -1 : +1;
This won't work if the number is longer than fits in an integer.
> + }
> +
> + return *(unsigned char *)psz_s1 < *(unsigned char *)psz_s2 ? -1 : +1;
This breaks case-insensitiveness.
> +
> +}
Also a sorting function must define a (non-strict) total order, which this
function does not.
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list