fixed segfault if the root of the airsonic folder has music file
This commit is contained in:
parent
93b4711d75
commit
647b106a7c
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
VERSION=1.2.0
|
||||
|
||||
CFLAGS+= -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\
|
||||
CFLAGS+= -g3 -O2 -Wall -Wextra -Wshadow -rdynamic -D_GNU_SOURCE\
|
||||
-D_FILE_OFFSET_BITS=64 -DVERSION=\"$(VERSION)\"\
|
||||
`pkg-config --cflags-only-I gumbo libcurl fuse uuid expat`
|
||||
LIBS = -pthread -lgumbo -lcurl -lfuse -lcrypto -luuid -lexpat
|
||||
|
|
10
src/sonic.c
10
src/sonic.c
|
@ -139,6 +139,7 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem,
|
|||
int linkname_set = 0;
|
||||
|
||||
for (int i = 0; attr[i]; i += 2) {
|
||||
printf("%s: %s\n", attr[i], attr[i+1]);
|
||||
if (!strcmp("id", attr[i])) {
|
||||
link->sonic_id = atoi(attr[i+1]);
|
||||
link->sonic_id_str = calloc(MAX_FILENAME_LEN, sizeof(char));
|
||||
|
@ -164,8 +165,13 @@ static void XMLCALL XML_process_single_element(void *data, const char *elem,
|
|||
*/
|
||||
if (!strcmp("path", attr[i])) {
|
||||
memset(link->linkname, 0, MAX_FILENAME_LEN);
|
||||
strncpy(link->linkname, strrchr(attr[i+1], '/') + 1,
|
||||
MAX_FILENAME_LEN);
|
||||
/* Skip to the last '/' if it exists */
|
||||
char *s = strrchr(attr[i+1], '/');
|
||||
if (s) {
|
||||
strncpy(link->linkname, s + 1, MAX_FILENAME_LEN);
|
||||
} else {
|
||||
strncpy(link->linkname, attr[i+1], MAX_FILENAME_LEN);
|
||||
}
|
||||
linkname_set = 1;
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue