[vlc-commits] commit: lua/net.c: revert [14707cbaca9fa] and fix properly ( Rafaël Carré )

git at videolan.org git at videolan.org
Mon May 10 17:05:41 CEST 2010


vlc | branch: master | Rafaël Carré <rafael.carre at gmail.com> | Mon May 10 17:04:05 2010 +0200| [087442fc1e36298dfbef018401b39d72249a17a9] | committer: Rafaël Carré 

lua/net.c: revert [14707cbaca9fa] and fix properly

Always return 1 argument, but avoid pushing 0xffffffff bytes on the stack
Also fix vlclua_fd_read()

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

 modules/misc/lua/libs/net.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c
index b5227d2..c23f475 100644
--- a/modules/misc/lua/libs/net.c
+++ b/modules/misc/lua/libs/net.c
@@ -184,14 +184,9 @@ static int vlclua_net_recv( lua_State *L )
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len = luaL_optint( L, 2, 1 );
     char psz_buffer[i_len];
-    i_len = recv( i_fd, psz_buffer, i_len, 0 );
-    if( i_len > 0 )
-    {
-        lua_pushlstring( L, psz_buffer, i_len );
-        return 1;
-    }
-    else
-        return 0;
+    ssize_t i_ret = recv( i_fd, psz_buffer, i_len, 0 );
+    lua_pushlstring( L, psz_buffer, (i_ret >= 0) ? i_ret : 0 );
+    return 1;
 }
 
 /*****************************************************************************
@@ -261,8 +256,8 @@ static int vlclua_fd_read( lua_State *L )
     int i_fd = luaL_checkint( L, 1 );
     size_t i_len = luaL_optint( L, 2, 1 );
     char psz_buffer[i_len];
-    i_len = read( i_fd, psz_buffer, i_len );
-    lua_pushlstring( L, psz_buffer, i_len );
+    ssize_t i_ret = read( i_fd, psz_buffer, i_len );
+    lua_pushlstring( L, psz_buffer, (i_ret >= 0) ? i_ret : 0 );
     return 1;
 }
 



More information about the vlc-commits mailing list