1. Shlomi Fish
  2. perl-XML-LibXML

Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed d58091c

Modified Files:
perl-libxml-mm.c
o fixed Sv2C() so empty strings will cause no segfaults anymore

  • Participants
  • Parent commits dca6352
  • Branches default

Comments (0)

Files changed (1)

File perl-libxml-mm.c

View file
  • Ignore whitespace
         if ( encoding == NULL || xmlStrcmp( encoding, "UTF8" ) == 0 ) {
             /* create an UTF8 string. */       
             STRLEN len = 0;
-            /* xmlChar *tstr = string; */
-
             xs_warn("set UTF8 string");
-            /* find out about the lenght */
-            /* while ( *tstr++ != 0 ); */
-            /* len = tstr - string; */ /* we need BYTE length */
             len = xmlStrlen( string );
             /* create the SV */
             retval = newSVpvn( (char *)xmlStrdup(string), len );
 Sv2C( SV* scalar, const xmlChar *encoding )
 {
     xmlChar *retval = NULL;
-
+    xs_warn("sv2c start!");
     if ( scalar != NULL && scalar != &PL_sv_undef ) {
         STRLEN len;
         xmlChar* string = xmlStrdup((xmlChar*)SvPV(scalar, len));
+        if ( xmlStrlen(string) > 0 ) {
+            xs_warn( "no undefs" );
 #ifdef HAVE_UTF8
-        if( !SvUTF8(scalar) && encoding != NULL ) {
-            xmlChar* ts;
-            ts= domEncodeString( encoding, string );
+            xs_warn( "use UTF8" );
+            if( !SvUTF8(scalar) && encoding != NULL ) {
+                xmlChar* ts;
+                xs_warn( "domEncodeString!" );
+                ts= domEncodeString( encoding, string );
+                xs_warn( "done!" );
+                if ( string != NULL ) 
+                    xmlFree(string);
+                string=ts;
+            }
+#endif
+            retval = xmlStrdup(string);
             xmlFree(string);
-            string=ts;
         }
-#endif
-        retval = xmlStrdup(string);
-        xmlFree(string);
     }
-
+    xs_warn("sv2c end!");
     return retval;
 }
 
 getSvNode( SV* perlnode ) 
 {
     xmlNodePtr retval = NULL;
+
     if ( perlnode != NULL && perlnode != &PL_sv_undef ) {
         retval = (xmlNodePtr)((ProxyObject*)SvIV((SV*)SvRV(perlnode)))->object;
     }
     if ( perlnode != NULL && perlnode != &PL_sv_undef ) {
         (SV*)((ProxyObject*)SvIV((SV*)SvRV(perlnode)))->extra = extra;
         if ( perlnode != extra ) { /* different objects */
-            SvREFCNT_inc(extra);
+           SvREFCNT_inc(extra);
         }
     }
     return perlnode;