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
b9961086
Commit
b9961086
authored
Nov 01, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag: don't return const string from fix_utf8()
Return NULL instead of the input value if there is nothing to fix. This way, the caller doesn't have to use the xfree() hack.
parent
aa33422d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
tag.c
src/tag.c
+13
-13
No files found.
src/tag.c
View file @
b9961086
...
...
@@ -343,22 +343,24 @@ int tag_equal(const struct tag *tag1, const struct tag *tag2)
return
1
;
}
static
inline
const
char
*
fix_utf8
(
const
char
*
str
,
size_t
*
length_r
)
{
const
char
*
temp
;
static
char
*
fix_utf8
(
const
char
*
str
,
size_t
*
length_r
)
{
char
*
temp
;
GError
*
error
=
NULL
;
gsize
written
;
assert
(
str
!=
NULL
);
if
(
g_utf8_validate
(
str
,
*
length_r
,
NULL
))
return
str
;
return
NULL
;
DEBUG
(
"not valid utf8 in tag: %s
\n
"
,
str
);
temp
=
g_convert
(
str
,
*
length_r
,
"utf-8"
,
"iso-8859-1"
,
NULL
,
&
written
,
&
error
);
if
(
temp
==
NULL
)
{
g_error_free
(
error
);
return
str
;
return
NULL
;
}
*
length_r
=
written
;
...
...
@@ -401,18 +403,17 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
const
char
*
value
,
size_t
len
)
{
unsigned
int
i
=
tag
->
numOfItems
;
char
*
duplicated
;
const
char
*
p
;
p
=
fix_utf8
(
value
,
&
len
);
p
=
duplicated
=
fix_utf8
(
value
,
&
len
);
if
(
p
==
NULL
)
p
=
value
;
if
(
memchr
(
p
,
'\n'
,
len
)
!=
NULL
)
{
char
*
duplicated
=
xmalloc
(
len
+
1
);
memcpy
(
duplicated
,
p
,
len
);
duplicated
[
len
]
=
'\0'
;
if
(
p
!=
value
)
xfree
(
p
);
if
(
duplicated
==
NULL
)
p
=
duplicated
=
g_strndup
(
p
,
len
);
stripReturnChar
(
duplicated
);
p
=
duplicated
;
}
tag
->
numOfItems
++
;
...
...
@@ -433,8 +434,7 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
tag
->
items
[
i
]
=
tag_pool_get_item
(
type
,
p
,
len
);
pthread_mutex_unlock
(
&
tag_pool_lock
);
if
(
p
!=
value
)
xfree
(
p
);
g_free
(
duplicated
);
}
void
tag_add_item_n
(
struct
tag
*
tag
,
enum
tag_type
itemType
,
...
...
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