G G
G G

Reputation: 1069

Crash in strdup() on Ubuntu

My C program gives segmentation fault when I try to run on Ubuntu.Here is the stack trace.Any help is appreciated

0  0x015383f1 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1  0x01538075 in strdup () from /lib/tls/i686/cmov/libc.so.6
#2  0x00c0a4af in cvtToString (ign=0xc10b80, target=0x83ba0a8, off=56, 
    source=0x0, setter=0xc044c3 <UxString_SetValue>) at xmlSerialPrimitives.c:28
#3  0x00c09adb in _setValue (xs=0x83b3520, inst=0x83ba0a8 "\020", prop=0xc103dc, 
    value=0x0) at xmlDeserializer.c:214
#4  0x00c09b71 in ctSetValue (xs=0x83b3520, property=0xc103dc, parent=0x83ba0a8, 
    val=0x0) at xmlDeserializer.c:237
#5  0x00c0a1aa in _closeElement (xs=0x83b3520, element=0x83ba1a0)
    at xmlDeserializer.c:419
#6  0x00c0a3da in xmlDeserialize (xs=0x83b3520, xtr=0x83b6218)
    at xmlDeserializer.c:533
#7  0x00c0ab14 in xmlDeserializeFromFile (xs=0x83b3520, 
    file=0x83b34f0 "/usr/v/xlayout.xml")
    at xmlSerializer.c:60
#8  0x00c07280 in load_uxUserModel (
    file=0x83b34f0 "/usr/v/xlayout.xml", data=0xbffff4dc)
    at UxUserModel.c:718
#9  0x00c073d0 in UxUserModel_LoadUserModel (name=0x8148e60 "x.xml")
    at UxUserModel.c:771
#10 0x00bf7f5d in UxModelLoad (umif=0x8397c58, filename=0x8148e60 "x.xml")

Here is the function where it is crashing

static int cvtToString( PCType * ign, void * target, int off, char * source, 
                        void_f    setter)
   {
        /* do we want to copy the string? */
        if (source && strncmp( source, "usermodel://", 12) == 0)
                return 0;
        source = strdup( source);
        if (setter)
               (*setter)( target, source);
        else
               (void) memcpy( target+off, &source, sizeof(char*));

        return 1;
   }

Upvotes: 1

Views: 1306

Answers (1)

wildplasser
wildplasser

Reputation: 44250

if (!source || !strncmp( source, "usermodel://", 12))
            return 0;

BTW: this line:

(void) memcpy( target+off, &source, sizeof(char*));

Attempts to performs arithmetic on a void pointer. The compiler should (at least) complain.

Upvotes: 1

Related Questions