[vlc-devel] [PATCH] Return null when vlc.strings.from_charset charset is invalid

Edward Wang edward.c.wang at compdigitec.com
Mon Jan 9 03:54:58 CET 2012


Show a debug warning and return "nil" when the charset requested is invalid.

Close #4815

---
 modules/lua/libs/strings.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/modules/lua/libs/strings.c b/modules/lua/libs/strings.c
index 88c5f0e..18f170d 100644
--- a/modules/lua/libs/strings.c
+++ b/modules/lua/libs/strings.c
@@ -137,10 +137,18 @@ static int vlclua_from_charset( lua_State *L )
     const char *psz_input = luaL_checklstring( L, 2, &i_in_bytes );
     if( i_in_bytes == 0 ) return vlclua_error( L );
 
+    vlc_object_t *p_this = vlclua_get_this( L );
+
     const char *psz_charset = luaL_checkstring( L, 1 );
     char *psz_output = FromCharset( psz_charset, psz_input, i_in_bytes );
-    lua_pushstring( L, psz_output ? psz_output : "" );
-    free( psz_output );
+    if( psz_output == NULL ) {
+        msg_Dbg( p_this, "vlc.strings.from_charset: charset %s is unsupported",
+                 psz_charset );
+        lua_pushnil( L );
+    } else {
+        lua_pushstring( L, psz_output );
+        free( psz_output );
+    }
     return 1;
 }
 
-- 
1.7.5.4




More information about the vlc-devel mailing list