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
d5be3cce
Commit
d5be3cce
authored
Mar 19, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text_input_stream: detect end-of-file
Fixes endless loop when the last line of a text file was not terminated (bug 3470).
parent
8dcefaf2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
text_input_stream.c
src/text_input_stream.c
+17
-2
No files found.
src/text_input_stream.c
View file @
d5be3cce
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <glib.h>
#include <glib.h>
#include <assert.h>
#include <string.h>
#include <string.h>
struct
text_input_stream
{
struct
text_input_stream
{
...
@@ -67,7 +68,12 @@ text_input_stream_read(struct text_input_stream *tis)
...
@@ -67,7 +68,12 @@ text_input_stream_read(struct text_input_stream *tis)
do
{
do
{
dest
=
fifo_buffer_write
(
tis
->
buffer
,
&
length
);
dest
=
fifo_buffer_write
(
tis
->
buffer
,
&
length
);
if
(
dest
!=
NULL
)
{
if
(
dest
!=
NULL
&&
length
>=
2
)
{
/* reserve one byte for the null terminator if
the last line is not terminated by a
newline character */
--
length
;
nbytes
=
input_stream_lock_read
(
tis
->
is
,
dest
,
length
,
nbytes
=
input_stream_lock_read
(
tis
->
is
,
dest
,
length
,
&
error
);
&
error
);
if
(
nbytes
>
0
)
if
(
nbytes
>
0
)
...
@@ -77,13 +83,22 @@ text_input_stream_read(struct text_input_stream *tis)
...
@@ -77,13 +83,22 @@ text_input_stream_read(struct text_input_stream *tis)
g_error_free
(
error
);
g_error_free
(
error
);
return
NULL
;
return
NULL
;
}
}
}
}
else
nbytes
=
0
;
src
=
fifo_buffer_read
(
tis
->
buffer
,
&
length
);
src
=
fifo_buffer_read
(
tis
->
buffer
,
&
length
);
if
(
src
==
NULL
)
if
(
src
==
NULL
)
return
NULL
;
return
NULL
;
p
=
memchr
(
src
,
'\n'
,
length
);
p
=
memchr
(
src
,
'\n'
,
length
);
if
(
p
==
NULL
&&
nbytes
==
0
)
{
/* end of file (or line too long): terminate
the current line */
dest
=
fifo_buffer_write
(
tis
->
buffer
,
&
nbytes
);
assert
(
dest
!=
NULL
);
*
(
char
*
)
dest
=
'\n'
;
fifo_buffer_append
(
tis
->
buffer
,
1
);
}
}
while
(
p
==
NULL
);
}
while
(
p
==
NULL
);
length
=
p
-
src
+
1
;
length
=
p
-
src
+
1
;
...
...
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