[vlc-commits] file out: avoid integer to pointer conversion
Rémi Denis-Courmont
git at videolan.org
Tue Nov 20 21:34:13 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 20 21:23:52 2018 +0200| [859668b3f2d31a938ae1c4561fa009d4e71b073c] | committer: Rémi Denis-Courmont
file out: avoid integer to pointer conversion
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=859668b3f2d31a938ae1c4561fa009d4e71b073c
---
modules/access_output/file.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/modules/access_output/file.c b/modules/access_output/file.c
index da419f2810..b1d563370c 100644
--- a/modules/access_output/file.c
+++ b/modules/access_output/file.c
@@ -64,11 +64,11 @@
*****************************************************************************/
static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
{
+ int *fdp = p_access->p_sys, fd = *fdp;
ssize_t val;
do
- val = read( (intptr_t)p_access->p_sys, p_buffer->p_buffer,
- p_buffer->i_buffer );
+ val = read(fd, p_buffer->p_buffer, p_buffer->i_buffer);
while (val == -1 && errno == EINTR);
return val;
}
@@ -78,12 +78,12 @@ static ssize_t Read( sout_access_out_t *p_access, block_t *p_buffer )
*****************************************************************************/
static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
{
+ int *fdp = p_access->p_sys, fd = *fdp;
size_t i_write = 0;
while( p_buffer )
{
- ssize_t val = write ((intptr_t)p_access->p_sys,
- p_buffer->p_buffer, p_buffer->i_buffer);
+ ssize_t val = write(fd, p_buffer->p_buffer, p_buffer->i_buffer);
if (val <= 0)
{
if (errno == EINTR)
@@ -111,7 +111,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
static ssize_t WritePipe(sout_access_out_t *access, block_t *block)
{
- int fd = (intptr_t)access->p_sys;
+ int *fdp = access->p_sys, fd = *fdp;
ssize_t total = 0;
while (block != NULL)
@@ -150,7 +150,7 @@ static ssize_t WritePipe(sout_access_out_t *access, block_t *block)
#ifdef S_ISSOCK
static ssize_t Send(sout_access_out_t *access, block_t *block)
{
- int fd = (intptr_t)access->p_sys;
+ int *fdp = access->p_sys, fd = *fdp;
size_t total = 0;
while (block != NULL)
@@ -189,7 +189,9 @@ static ssize_t Send(sout_access_out_t *access, block_t *block)
*****************************************************************************/
static int Seek( sout_access_out_t *p_access, off_t i_pos )
{
- return lseek( (intptr_t)p_access->p_sys, i_pos, SEEK_SET );
+ int *fdp = p_access->p_sys, fd = *fdp;
+
+ return lseek(fd, i_pos, SEEK_SET);
}
static int Control( sout_access_out_t *p_access, int i_query, va_list args )
@@ -232,7 +234,11 @@ static const char *const ppsz_sout_options[] = {
static int Open( vlc_object_t *p_this )
{
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
- int fd;
+ int fd;
+ int *fdp = vlc_obj_malloc(p_this, sizeof (*fdp));
+
+ if (unlikely(fdp == NULL))
+ return VLC_ENOMEM;
config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
@@ -316,6 +322,9 @@ static int Open( vlc_object_t *p_this )
return VLC_EGENERIC;
}
+ *fdp = fd;
+ p_access->p_sys = fdp;
+
struct stat st;
if (fstat (fd, &st))
@@ -345,7 +354,6 @@ static int Open( vlc_object_t *p_this )
p_access->pf_seek = NULL;
}
p_access->pf_control = Control;
- p_access->p_sys = (void *)(intptr_t)fd;
msg_Dbg( p_access, "file access output opened (%s)", p_access->psz_path );
if (append)
@@ -360,9 +368,9 @@ static int Open( vlc_object_t *p_this )
static void Close( vlc_object_t * p_this )
{
sout_access_out_t *p_access = (sout_access_out_t*)p_this;
+ int *fdp = p_access->p_sys, fd = *fdp;
- vlc_close( (intptr_t)p_access->p_sys );
-
+ vlc_close(fd);
msg_Dbg( p_access, "file access output closed" );
}
More information about the vlc-commits
mailing list