Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
03524fb8
Commit
03524fb8
authored
Jan 03, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag: use g_strescape() to eliminate evil characters
This always allocates strings on the heap, but we can delete the stripReturnChar() function now.
parent
d342e338
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
27 deletions
+22
-27
tag.c
src/tag.c
+22
-18
utils.c
src/utils.c
+0
-7
utils.h
src/utils.h
+0
-2
No files found.
src/tag.c
View file @
03524fb8
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
#include "tag.h"
#include "tag.h"
#include "tag_internal.h"
#include "tag_internal.h"
#include "tag_pool.h"
#include "tag_pool.h"
#include "utils.h"
#include "log.h"
#include "log.h"
#include "conf.h"
#include "conf.h"
#include "song.h"
#include "song.h"
...
@@ -358,7 +357,7 @@ int tag_equal(const struct tag *tag1, const struct tag *tag2)
...
@@ -358,7 +357,7 @@ int tag_equal(const struct tag *tag1, const struct tag *tag2)
}
}
static
char
*
static
char
*
fix_utf8
(
const
char
*
str
,
size_t
*
length_r
)
fix_utf8
(
const
char
*
str
,
size_t
length
)
{
{
char
*
temp
;
char
*
temp
;
GError
*
error
=
NULL
;
GError
*
error
=
NULL
;
...
@@ -366,18 +365,17 @@ fix_utf8(const char *str, size_t *length_r)
...
@@ -366,18 +365,17 @@ fix_utf8(const char *str, size_t *length_r)
assert
(
str
!=
NULL
);
assert
(
str
!=
NULL
);
if
(
g_utf8_validate
(
str
,
*
length_r
,
NULL
))
if
(
g_utf8_validate
(
str
,
length
,
NULL
))
return
NULL
;
return
NULL
;
DEBUG
(
"not valid utf8 in tag: %s
\n
"
,
str
);
DEBUG
(
"not valid utf8 in tag: %s
\n
"
,
str
);
temp
=
g_convert
(
str
,
*
length_r
,
"utf-8"
,
"iso-8859-1"
,
temp
=
g_convert
(
str
,
length
,
"utf-8"
,
"iso-8859-1"
,
NULL
,
&
written
,
&
error
);
NULL
,
&
written
,
&
error
);
if
(
temp
==
NULL
)
{
if
(
temp
==
NULL
)
{
g_error_free
(
error
);
g_error_free
(
error
);
return
NULL
;
return
NULL
;
}
}
*
length_r
=
written
;
return
temp
;
return
temp
;
}
}
...
@@ -413,22 +411,28 @@ void tag_end_add(struct tag *tag)
...
@@ -413,22 +411,28 @@ void tag_end_add(struct tag *tag)
#endif
#endif
}
}
static
char
*
fix_tag_value
(
const
char
*
p
,
size_t
length
)
{
char
*
utf8
,
*
escaped
;
utf8
=
fix_utf8
(
p
,
length
);
if
(
utf8
==
NULL
)
utf8
=
g_strndup
(
p
,
length
);
escaped
=
g_strescape
(
utf8
,
NULL
);
g_free
(
utf8
);
return
escaped
;
}
static
void
appendToTagItems
(
struct
tag
*
tag
,
enum
tag_type
type
,
static
void
appendToTagItems
(
struct
tag
*
tag
,
enum
tag_type
type
,
const
char
*
value
,
size_t
len
)
const
char
*
value
,
size_t
len
)
{
{
unsigned
int
i
=
tag
->
numOfItems
;
unsigned
int
i
=
tag
->
numOfItems
;
char
*
duplicated
;
char
*
p
;
const
char
*
p
;
p
=
duplicated
=
fix_utf8
(
value
,
&
len
);
if
(
p
==
NULL
)
p
=
value
;
if
(
memchr
(
p
,
'\n'
,
len
)
!=
NULL
)
{
if
(
duplicated
==
NULL
)
p
=
duplicated
=
g_strndup
(
p
,
len
);
stripReturnChar
(
duplicated
);
p
=
fix_tag_value
(
value
,
len
);
}
tag
->
numOfItems
++
;
tag
->
numOfItems
++
;
...
@@ -445,10 +449,10 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
...
@@ -445,10 +449,10 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
}
}
g_mutex_lock
(
tag_pool_lock
);
g_mutex_lock
(
tag_pool_lock
);
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
p
,
len
);
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
p
,
strlen
(
p
)
);
g_mutex_unlock
(
tag_pool_lock
);
g_mutex_unlock
(
tag_pool_lock
);
g_free
(
duplicated
);
g_free
(
p
);
}
}
void
tag_add_item_n
(
struct
tag
*
tag
,
enum
tag_type
itemType
,
void
tag_add_item_n
(
struct
tag
*
tag
,
enum
tag_type
itemType
,
...
...
src/utils.c
View file @
03524fb8
...
@@ -40,13 +40,6 @@
...
@@ -40,13 +40,6 @@
#include <windows.h>
#include <windows.h>
#endif
#endif
void
stripReturnChar
(
char
*
string
)
{
while
(
string
&&
(
string
=
strchr
(
string
,
'\n'
)))
{
*
string
=
' '
;
}
}
void
my_usleep
(
long
usec
)
void
my_usleep
(
long
usec
)
{
{
#ifdef WIN32
#ifdef WIN32
...
...
src/utils.h
View file @
03524fb8
...
@@ -36,8 +36,6 @@
...
@@ -36,8 +36,6 @@
} while (0)
} while (0)
#endif
/* !assert_static */
#endif
/* !assert_static */
void
stripReturnChar
(
char
*
string
);
void
my_usleep
(
long
usec
);
void
my_usleep
(
long
usec
);
/* trivial functions, keep them inlined */
/* trivial functions, keep them inlined */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment