[vlc-commits] lua_demux: return nil when read/peek fails.

Rémi Duraffort git at videolan.org
Sun Jun 26 23:36:15 CEST 2011


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sun Jun 26 21:17:11 2011 +0200| [1202f7e6804f4ba445d409c279f4bebb80746052] | committer: Rémi Duraffort

lua_demux: return nil when read/peek fails.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1202f7e6804f4ba445d409c279f4bebb80746052
---

 modules/lua/demux.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/modules/lua/demux.c b/modules/lua/demux.c
index f924512..5f3d1e9 100644
--- a/modules/lua/demux.c
+++ b/modules/lua/demux.c
@@ -60,8 +60,12 @@ static int vlclua_demux_peek( lua_State *L )
     demux_t *p_demux = (demux_t *)vlclua_get_this( L );
     int n = luaL_checkint( L, 1 );
     const uint8_t *p_peek;
+
     int i_peek = stream_Peek( p_demux->s, &p_peek, n );
-    lua_pushlstring( L, (const char *)p_peek, i_peek );
+    if( i_peek > 0 )
+        lua_pushlstring( L, (const char *)p_peek, i_peek );
+    else
+        lua_pushnil( L );
     return 1;
 }
 
@@ -71,9 +75,16 @@ static int vlclua_demux_read( lua_State *L )
     const uint8_t *p_read;
     int n = luaL_checkint( L, 1 );
     int i_read = stream_Peek( p_demux->s, &p_read, n );
-    lua_pushlstring( L, (const char *)p_read, i_read );
-    int i_seek = stream_Read( p_demux->s, NULL, i_read );
-    assert(i_read==i_seek);
+
+    if( i_read > 0 )
+    {
+        lua_pushlstring( L, (const char *)p_read, i_read );
+        int i_seek = stream_Read( p_demux->s, NULL, i_read );
+        assert( i_read == i_seek );
+    }
+    else
+        lua_pushnil( L );
+
     return 1;
 }
 



More information about the vlc-commits mailing list